我如何通过JObject枚举? [英] How do I enumerate through a JObject?
问题描述
我试图确定如何访问是我JObject数据,我不能为我的生命决定如何使用它。
I'm trying to determine how to access the data that is in my JObject and I can't for the life of me determine how to use it.
JObject Object = (JObject)Response.Data["my_key"];
我可以把它打印到控制台做Console.WriteLine(对象),我看到的数据,是这样的:
I can print it to the console doing Console.WriteLine(Object) and I see the data, it looks like:
{
"my_data" : "more of my string data"
...
}
但我不知道如何只遍历/通过它枚举,人有有任何想法吗?我在这样的损失是正确的,现在
But I have NO idea how to just iterate/enumerate through it, anyone have any ideas? I'm at such a loss right now.
推荐答案
如果你看的 JObject newtonking.com/projects/json/help/html/T_Newtonsoft_Json_Linq_JObject.htm\">the文件,你会看到,它实现了的IEnumerable< KeyValuePair<字符串,JToken>>
。所以,你可以简单地使用迭代它一个的foreach
:
If you look at the documentation for JObject
, you will see that it implements IEnumerable<KeyValuePair<string, JToken>>
. So, you can iterate over it simply using a foreach
:
foreach (var x in obj)
{
string name = x.Key;
JToken value = x.Value;
…
}
这篇关于我如何通过JObject枚举?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!