This is a very simple question but can't seem to find a direct answer. I read in a single JSON object. I then want to parse it and be able to directly address a token or a value and then format it for writing a file output, which I will use in another application. I am using C# and the Newtonsoft library.
My code:
JsonTextReader reader = new JsonTextReader(re);
while (reader.Read())
{
if (reader.Value != null)
Console.WriteLine("Value: {0}", "This is the value <Tags>: " + reader.Value);
}
How can I address each line? for example, desc and then Gets a reference to the game world. This must be so commoplace.
Thanks,
johnh
Use the JArray
and JObject
objects instead, like this:
var json = System.IO.File.ReadAllText("YourJSONFilePath");
var objects = JArray.Parse(json);
foreach(JObject root in objects)
{
foreach(KeyValuePair<String, JToken> tag in root)
{
var tagName = tag.Key;
Console.WriteLine("Value: {0}", "This is the value <Tags>: " + tagName);
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With