JSON.Net - cannot deserialize the current json object (e.g. {“name”:“value”}) into type 'system.collections.generic.list`1

隐身守侯 提交于 2019-12-04 06:05:11
Radim Köhler

In this case, you should ask Deserializer for IDictionary<string, Match>

var mList= JsonConvert.DeserializeObject<IDictionary<string, Match>>(jsonstr);

And the first element would have key "40" and the value will be the Match instance

Other words this part:

"40": {
    "name": "Team A vs Team B",
    "value": {
      "home": 1,
      "away": 0
    }

will result in KeyValuePair:

key - "40"
value - Match { Name = "Team",  ... }
"50": {
         "name": "Team A vs Team D",
         "value": {
                    "home": 0,
                    "away": 2
                  }
      }

The desirializer works correctly. In this json code value is an object. Try with this:

"50": {
         "name": "Team A vs Team D",
         "value": [{
                     "home": 0,
                     "away": 2
                  }]
      }

In this json code value is declared as an array of objects. Notice the [ and ]

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!