简体   繁体   English

杰森到C#反序列化-属性名称是一个整数-如何解决?

[英]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. 好的,我正在尝试从API获取数据,并且可以正常工作。 This is the data I get: json data 这是我得到的数据: json数据

Yet the only problem is, when I try to access the "7" and "10" property in order to get "rankPoints", I get a bug: 唯一的问题是,当我尝试访问“ 7”和“ 10”属性以获取“ rankPoints”时,出现一个错误:

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[])'' Microsoft.CSharp.RuntimeBinder.RuntimeBinderException:'在以下方法或属性之间的调用是不明确的:'​​System.Console.WriteLine(string,params object [])'和'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? 我猜它不能访问属性,因为它是一个int? But I cant change the data, since it is from an API. 但是我无法更改数据,因为它来自API。

Thank you, MV 谢谢MV

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

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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