开发者

How to deserialize json with nested Dictionaries?

For some endpoints SimpleGeo.com returns something like this:

{
    "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":""                  
            }             
        ]          
    }     
}

(see http://simplegeo.com/docs/api-endpoints/simplegeo-features#get-detailed-information).

Now I have a small problem deserializing the 'properties' part. If I use e.g. a type of Dictionary it conve开发者_JAVA技巧rts it to a nice dictionary, but the 'classifiers' value is just one {} string.

Is there any way to tell json.net to deserialize sub-arrays into yet another Dictionary etc etc? Basically there's an amount of plain key/values in that return, but I do know that there might be more than just that 'classifiers' sub-array (see the 'tags'), and maybe the depth goes even further in the values...

So basically what I was wondering is, how do I properly deserialize the properties part? Any suggestions? I don't mind writing my own JsonConverter, but maybe there is already a way that works without it.


I've found a solution for a similar question over here: Json.NET: Deserializing nested dictionaries.

It uses a custom JsonConverter and I don't see a way to do without it.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜