我正在尝试DeserializeObject,但不知道如何到达方括号内的对象[]
dynamic response = null;
response = JsonConvert.DeserializeObject(apiResponseContent);
apiResponseContent =
"CasinoId: " + response.Result.FirstName + "\r\n" +
"PlayerId: " + response.Result.Id我正试图分析它的反应:
"{\"Status\":{\"ErrorCode\":0,\"ErrorName\":\"SUCCEED\",\"ErrorMessage\":\"\",\"ReferenceNumber\":\"\"},\"Result\":[{\"FirstName\":Adam,\"Id\":6161999\"}]}"会感谢你的回答
发布于 2015-08-10 13:10:35
我相信您可以使用键集合访问JSON对象中的字段,因此响应“keynamehere”。
但是最好的方法是创建一个模仿JSON对象和字段的对象,然后您可以反序列化到该对象,然后它将映射这些字段。(即:JsonConvert.DeserializeObject<YOUROBJECTHERE>(apiResponseContent))
请更详细地查看一些关于如何做到这一点的参考链接:http://www.newtonsoft.com/json/help/html/DeserializeObject.htm
Deserializing JSON data to C# using JSON.NET
如果你想变得更花哨一点,你可以创建你自己的自定义转换器:Deserialize the JSON where the values are field names with JSON.NET
https://stackoverflow.com/questions/31920254
复制相似问题