Parsing nested JSON objects with JSON.NET

前端 未结 1 573
南方客
南方客 2021-01-02 02:17

My JSON feed has nested objects like this:

{
\"id\": 1765116,
\"name\": \"StrozeR\",
\"birth\": \"2009-08-12\",
\"avatar\": \"http:\\/\\/static.erepublik.com         


        
1条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-01-02 03:11

    Like the error message says, your rank property in the .NET class is a List, but in your JSON it's just a nested object, not an array. Change it to just a Rank instead of a List.

    Arrays in JSON (or any Javascript, really) are enclosed in []. The {} characters specify a single object. The CLR type has to roughly match the JSON type in order to deserialize. Object to object, array to array.

    0 讨论(0)
提交回复
热议问题