【发布时间】:2015-04-10 07:11:22
【问题描述】:
我通过调用格式如下的服务获取 JSON 数据:
[
[
{
"AgentStatus": "- Active",
"Basement": "None",
"BasementType": "",
"Baths": "4",
"BathsHalf": "1",
"Beds": "6"
},
[
"372010-1.jpg"
]
],
[
{
"AgentStatus": "- Active",
"Basement": "Finished,Full",
"BasementType": "FULL FINISHED",
"Baths": "2",
"BathsHalf": "1",
"Beds": "3"
},
[
"377388-1.jpg",
"377388-2.jpg",
"377388-12.jpg"
]
]
]
为了解析这个 JSON,我制作了这样的类:
public class RetsProperty
{
public PropertyAttributes PropAttributes { get; set; }
public string[] ImgUrls { get; set; }
}
public class PropertyAttributes
{
public string AgentStatus { get; set; }
public string Basement { get; set; }
public string BasementType { get; set; }
public string Baths { get; set; }
public string BathsHalf { get; set; }
public string Beds { get; set; }
}
我已经使用 Newtonsoft Json 反序列化 JSON 数据
var retsPropertyItems = Newtonsoft.Json.JsonConvert.DeserializeObject<List<RetsProperty>>(propertyJsonString);
但它无法解析它返回以下错误:
我认为是因为我无法正确创建类。
那么我该如何格式化我的课程呢? 还是可以像我一样绘制地图?
谢谢
【问题讨论】:
-
这个 json 是否应该是
RetsProperty的列表?,json 对我来说似乎格式不正确(看起来是提供一个二维对象数组) -
您可以访问 JSON 吗?将内部数组更改为对象
-
不,我没有任何访问权限。我从服务电话中得到它。
-
您可能会遇到困难,然后基本上您有一个带有
PropertyAttributes对象和字符串数组的二维数组,每个数组中有一个对象([ [ PropertyAttributes, [strings] ], [ PropertyAttributes, [strings] ] ]),它可能仍然可行,只是不行就像获取RetsProperty的单个列表一样简单
标签: c# json asp.net-mvc web-services