I have the following json:
{
"key445" : {
"text" : "cat",
"id" : 445
},
"key457" : {
"text" : "mouse",
"id" : 457
},
"key458" : {
"text" : "rodent",
"id" : 458
}
}
I am trying extract text
and id
into a List<TextIdentifier>
(a class with string and an int), or even separately into List<string>
and List<int>
.
I read the text into JObject using JObject.Parse
method. However, I can't figure out how to get to the text and id nodes. I've tried the following but it returns nothing.
var textTokens = o.SelectTokens("/*/text");
var idTokens = o.SelectTokens("/*/id");
How can I get to the tokens I want?
JObject
rather than parsing intoDictionary<string, TextIdentifier>
which I suspect would just work immediately?TextIdentifier
has writable properties forText
andId
, that's all you need to do :)Dictionary<string, TextIdentifier>
and then if you only need the values, just use theValues
property. Unless you need them in the order of the JSON file, which would be quite fragile. (Adding a sample now.)