对于某些端点 SimpleGeo.com 返回如下内容:
{
"geometry":{
"type":"Point",
"coordinates":[
-122.421583,
37.795027
]
},
"type":"Feature",
"id":SG_5JkVsYK82eLj26eomFrI7S_37.795027_-122.421583@1291796505,
"properties":{
"province":"CA",
"city":"San Francisco",
"name":"Bell Tower",
"tags":[],
"country":"US",
"phone":"+1 415 567 9596",
"href": http://api.simplegeo.com/1.0/features/SG_5JkVsYK82eLj26eomFrI7S_37.795027_-122.421583@1291796505.json,
"address":"1900 Polk St",
"owner":"simplegeo",
"postcode":"94109",
"classifiers":[
{
"category":"Restaurant",
"type":"Food & Drink",
"subcategory":""
}
]
}
}
(见 http://simplegeo.com/docs/api-endpoints/simplegeo-features#get-detailed-information)。
现在我在反序列化“属性”部分时遇到了一个小问题。如果我使用例如一种类型的字典,它将它转换为一个不错的字典,但 'classifiers' 值只是一个 {} 字符串。
有没有办法告诉 json.net 将子数组反序列化为另一个字典等?基本上,该返回中有大量普通的键/值,但我知道可能不仅仅是“分类器”子数组(参见“标签”),而且值中的深度可能更远。 ..
所以基本上我想知道的是,我如何正确反序列化属性部分?有什么建议?我不介意编写我自己的 JsonConverter,但也许已经有一种没有它的方法。
最佳答案
我在这里找到了类似问题的解决方案:
Json.NET: Deserializing nested dictionaries .
它使用自定义 JsonConverter,我看不出没有它的方法。
关于json - 如何使用嵌套字典反序列化 json?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4599342/