简体   繁体   中英

Json to C# Deserialize - Property name is an int - how to fix?

Okay so I'm trying to get data from an API, and it works. This is the data I get: json data

Yet the only problem is, when I try to access the "7" and "10" property in order to get "rankPoints", I get a bug:

Microsoft.CSharp.RuntimeBinder.RuntimeBinderException: 'The call is ambiguous between the following methods or properties: 'System.Console.WriteLine(string, params object[])' and 'System.Console.WriteLine(char[])''

This is the code that works:

var x = oMycustomclassname["rankedSeasons"];

This is the code that does not work:

var x = oMycustomclassname["rankedSeasons.7.10.rankPoints"];

I'm guessing it cant access the property because it is an int? But I cant change the data, since it is from an API.

Thank you, MV

每个子项都是另一个json对象,可以像字典一样访问

var x = (int)oMycustomclassname["rankedSeasons"]["7"]["10"]["rankPoints"];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM