Json(JToken.Parse(响应)) returns 空数组
Json(JToken.Parse(response)) returns empty array
我已经使用 HttpClient 来使用 API,然后我从 response.Content.ReadAsStringAsync() 中得到序列化字符串形式的响应。结果如下所述,
"{\r\n \"responseCode\": 400,\r\n \"errors\": [\r\n {\r\n \"errorCode\": \"RPM400\",\r\n \"errorMessage\": \"A program already exists.\"\r\n }\r\n ]\r\n}"
我想反序列化为
{
"responseCode": 400,
"errors": [
{
"errorCode": "RPM400",
"errorMessage": "A program already exists."
}
]
}
然后我必须将它发送到 UI,ASP.Net MVC 5 ActionMethod 中的 return 类型是 ActionResult。
我尝试使用 Json(JObject.Parse(response)) 和 Json(JToken.Parse(response))但我在邮递员中收到如下空回复
[
[
[]
],
[
[
[
[
[]
],
[
[]
]
]
]
]
]
同一个 Json(JObject.Parse(response)) 正在另一个 ASP.Net Core 2 应用程序中工作。你能提供吗有什么帮助吗?
我使用了 Whosebug's 标记的答案,我不得不使用 using System.Web.Script.Serialization; 进行反序列化然后它起作用了,因为我的 .Net 框架是4.7.2
我已经使用 HttpClient 来使用 API,然后我从 response.Content.ReadAsStringAsync() 中得到序列化字符串形式的响应。结果如下所述,
"{\r\n \"responseCode\": 400,\r\n \"errors\": [\r\n {\r\n \"errorCode\": \"RPM400\",\r\n \"errorMessage\": \"A program already exists.\"\r\n }\r\n ]\r\n}"
我想反序列化为
{
"responseCode": 400,
"errors": [
{
"errorCode": "RPM400",
"errorMessage": "A program already exists."
}
]
}
然后我必须将它发送到 UI,ASP.Net MVC 5 ActionMethod 中的 return 类型是 ActionResult。
我尝试使用 Json(JObject.Parse(response)) 和 Json(JToken.Parse(response))但我在邮递员中收到如下空回复
[
[
[]
],
[
[
[
[
[]
],
[
[]
]
]
]
]
]
同一个 Json(JObject.Parse(response)) 正在另一个 ASP.Net Core 2 应用程序中工作。你能提供吗有什么帮助吗?
我使用了 Whosebug's 标记的答案,我不得不使用 using System.Web.Script.Serialization; 进行反序列化然后它起作用了,因为我的 .Net 框架是4.7.2