Getting access to ArrayList object

前端 未结 2 536
天命终不由人
天命终不由人 2021-01-27 23:19

I\'m developing an application that reads some JSON data and makes some statistics, but now I\'ve run into a problem.

I have a string like this:

{
\"posi         


        
2条回答
  •  刺人心
    刺人心 (楼主)
    2021-01-28 00:02

    You can use Linq to JSON (add Newtonsoft's JSON.NET from NuGet):

    JObject jo = JObject.Parse(json);
    var value = (string)jo["position"][1]["someKey1"]; // someVal3
    

    Another sample:

    JObject jo = JObject.Parse(json);
    JArray positions = (JArray)jo["position"];
    foreach (var item in positions)
    {
        // use (string)item["someKey1"]
        // use (string)item["someKey2"]
    }
    

提交回复
热议问题