我在解析从 Yahoo! 发送的 JSON 响应时遇到问题!占位符。我只需要 List LocalScopes。
我的类定义如下:
public class PlacemakerResponse
{
public Document document { get; set; }
public class Document
{
public List<LocalScope> localScopes { get; set; }
}
}
public class LocalScope
{
public String woeId { get; set; }
public String name { get; set; }
public Centroid centroid { get; set; }
public class Centroid
{
public String latitude { get; set; }
public String longitude { get; set; }
}
}
完整的 JSON 字符串如下。我在JSONLint验证了它,一切似乎都是有序的。
{
"processingTime": "0.00191",
"version": " build 110725",
"documentLength": "36",
"document": {
"0": {
"placeDetails": {
"placeId": "1",
"place": {
"woeId": "483446",
"type": "Town",
"name": "Misida, Malta Majjistral, MT",
"centroid": {
"latitude": "35.8956",
"longitude": "14.4892"
}
},
"placeReferenceIds": "1",
"matchType": "0",
"weight": "1",
"confidence": "10"
}
},
"1": {
"placeDetails": {
"placeId": "2",
"place": {
"woeId": "2450022",
"type": "Town",
"name": "Miami, FL, US",
"centroid": {
"latitude": "25.729",
"longitude": "-80.2374"
}
},
"placeReferenceIds": "2",
"matchType": "0",
"weight": "1",
"confidence": "10"
}
},
"administrativeScope": {
"woeId": "0",
"type": "Undefined",
"name": "",
"centroid": {
"latitude": "0",
"longitude": "0"
}
},
"geographicScope": {
"woeId": "1",
"type": "Supername",
"name": "Earth",
"centroid": {
"latitude": "0",
"longitude": "0"
}
},
"localScopes": [
{
"localScope": {
"woeId": "483446",
"type": "Town",
"name": "Misida, Malta Majjistral, MT (Town)",
"centroid": {
"latitude": "35.8956",
"longitude": "14.4892"
},
"southWest": {
"latitude": "35.8893",
"longitude": "14.472"
},
"northEast": {
"latitude": "35.9109",
"longitude": "14.4986"
},
"ancestors": [
{
"ancestor": {
"woeId": "24551414",
"type": "Locality",
"name": "Msida"
}
},
{
"ancestor": {
"woeId": "56043491",
"type": "Region",
"name": "Malta Majjistral"
}
},
{
"ancestor": {
"woeId": "23424897",
"type": "Country",
"name": "Malta"
}
}
]
}
},
{
"localScope": {
"woeId": "2450022",
"type": "Town",
"name": "Miami, FL, US (Town)",
"centroid": {
"latitude": "25.729",
"longitude": "-80.2374"
},
"southWest": {
"latitude": "25.5403",
"longitude": "-80.4469"
},
"northEast": {
"latitude": "25.9578",
"longitude": "-80.028"
},
"ancestors": [
{
"ancestor": {
"woeId": "12587815",
"type": "County",
"name": "Miami-Dade"
}
},
{
"ancestor": {
"woeId": "2347568",
"type": "State",
"name": "Florida"
}
},
{
"ancestor": {
"woeId": "23424977",
"type": "Country",
"name": "United States"
}
}
]
}
}
],
"extents": {
"center": {
"latitude": "35.8956",
"longitude": "14.4892"
},
"southWest": {
"latitude": "25.5403",
"longitude": "-80.4469"
},
"northEast": {
"latitude": "35.9109",
"longitude": "14.4986"
}
},
"referenceList": [
{
"reference": {
"woeIds": "483446",
"placeReferenceId": "1",
"placeIds": "1",
"start": "20",
"end": "25",
"isPlaintextMarker": "1",
"text": "Msida",
"type": "plaintext",
"xpath": ""
}
},
{
"reference": {
"woeIds": "2450022",
"placeReferenceId": "2",
"placeIds": "2",
"start": "30",
"end": "35",
"isPlaintextMarker": "1",
"text": "Miami",
"type": "plaintext",
"xpath": ""
}
}
]
}
}
当我做:List<LocalScope> places = (ser.Deserialize<PlacemakerResponse>(stringJSON)).document.localScopes;
地点列表有两个 LocalScope 对象,如 JSON 字符串(到目前为止一切顺利),但所有三个成员(woeId、name、centroid)都设置为 null!
我以前多次使用 JavaScriptSerializer 并且从未遇到任何问题,有人对我做错了什么有任何建议吗?
谢谢你。