【发布时间】:2017-01-02 09:40:27
【问题描述】:
我从一个公共 API 接收一个 JSON 对象,该对象的属性本身就是一个转义的 JSON 字符串。
{
"responses":[
{
"info":"keep \"this\" in a string",
"body":"{\"error\":{\"message\":\"Invalid command\",\"type\":\"Exception\",\"code\":123}}"
},
{
"info":"more \"data\" to keep in a string",
"body":"{\"error\":{\"message\":\"Other error\",\"type\":\"Exception\",\"code\":321}}"
}
]
}
如何将此属性转换为实际的 JSON 对象(未转义),以便使用 NewtonSoft Json.NET 反序列化整个响应?
【问题讨论】:
-
是否要将正文转换为 JSON?它已经在 JSON 中
-
我尝试过使用 Newtonsoft Json.NET 进行反序列化,但在尝试将主体转换为类时出现错误。
"Error converting value [JSON String] to type '[MyClass]'. Path 'responses[0].body', line 1, position 641." -
查看我的编辑。我修好了