I have some JSON data that looks like this:
{
"910719": {
"id": 910719,
"type": "asdf",
"ref_id": 7568
},
"910721": {
"id": 910721,
"type": "asdf",
"ref_id": 7568
},
"910723": {
"id": 910723,
"type": "asdf",
"ref_id": 7568
}
}
How can I parse this using JSON.net? I can first do this:
JObject jFoo = JObject.Parse(data);
I need to be able to iterate over each object in this list. I would like to be able to do something like this:
foreach (string ref_id in (string)jFoo["ref_id"]) {...}
or
foreach (JToken t in jFoo.Descendants())
{
Console.WriteLine((string)t["ref_id"]);
}
but of course that doesn't work. All the examples work great if you know the key while writing your code. It breaks down when you don't know the key in advance.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…