简体   繁体   中英

How to get data from a nested json in c#

{"data": {"day2": {"mId": "9ilrMdX15S", "votes": "2,893"},"day3": {"mId": "9ilert415S","votes": "2,343"}}}如何从一个JSON数据,例如获取数据(在“第2天”,即数据,或“第三天”),我也跟着问题的答案在这里> 附加JSON数据的ListView C#的脑罗杰斯但得到的答复仅JSON对象工作不适用于嵌套的 json。

Here's an example of how to navigate it:

foreach (JProperty day in JObject.Parse(json)["data"])
{
    string name = day.Name;
    string id = day.Value.Value<string>("mId");
    string votes = day.Value.Value<string>("votes");
} 

Thanks for all the response, i was able to solve the task using the SimpleJSON library by Bunny83 GitHub - Bunny83/SimpleJSON: A simple JSON parser in C#

        JSONNode data = JSON.Parse(//jsonData or Url//);
        string mId = data["data"]["day2"]["mId"].Value;
        string votes = data["data"]["day2"]["votes"].Value;

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