简体   繁体   English

如何从 C# 中的 JObject 中读取数组的名称

[英]How to Read Name of array in from JObject in C#

This is the array that i am getting from an api response and i want to read "591460000000352107" this value.这是我从 api 响应中获得的数组,我想读取“591460000000352107”这个值。 this is the key of array and that will be different in every response of api.这是数组的关键,在 api 的每个响应中都会有所不同。 so how can i read it from Jobject in C# {"response": { "result": [{"591460000000352107": [{"Middle_Name": "","EmailID":"prateek.chauhan@gmail.com","Expertise": ""}]}]}}那么我如何从 C# 中的 Jobject 中读取它{"response": { "result": [{"591460000000352107": [{"Middle_Name": "","EmailID":"prateek.chauhan@gmail.com","Expertise": ""}]}]}}

var jobj = JObject.Parse(json);
foreach (var result in (jobj["response"]["result"]))
    foreach (var key in (result as JObject).Properties())
        Console.WriteLine(key.Name);

You can iterate over the results and get the name of the keys您可以遍历结果并获取键的名称

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

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