【发布时间】:2017-11-03 14:41:39
【问题描述】:
我正在尝试从我的内容中获得特定的价值,但我不知道该怎么做。
我正在使用 RestSharp(C#) 运行我的 JSON 代码,但是当我执行命令时它返回错误。我需要从属性 errorMessage 中获取值。
var json = JsonConvert.SerializeObject(objectToUpdate);
var request = new RestRequest(Method.POST);
request.RequestFormat = DataFormat.Json;
request.AddCookie("authToken", token);
request.AddParameter("application/json", json, ParameterType.RequestBody);
var response = client.Execute<T>(request);
After execute this code my response return the below JSON:
{
"response":{},
"status":{
"success":false,
"detail":{
"errormessage":[{
"fieldName":"departmentCode",
"errorMessage":"Department code provided is already associated with another department",
"errorCode":"DUPLICATE_DEPARTMENT_CODE"
}],
"error":"Validation failure on request",
"operation":"internal",
"errorcode":"412"
}
}
}
【问题讨论】:
-
尝试“request.Parameters.Clear();”在 "request.AddCookie("authToken", token);"之前
-
可以看看stackoverflow.com/questions/11400879/…。其他 - 错误消息显示您的消息未通过验证 - 您在 departmentCode 中存在内容问题
-
你好@DarkoMaricProgramer,我的参数没有问题,我只需要从errorMessage获取信息保存在我的日志中。
-
我明白了...然后尝试:动态结果 = JObject.Parse(response); var detail = result.status.detail.errormessage; foreach(详细的 var 项){};