mskuratowski
mskuratowski

Reputation: 4124

Read JSON from string and get access to keys

Can I read JSON from string and iterate if I don't know what kind of key it stores?

Generally, it will be key value pair?

I know that I can use: dynamic dynamicJson = JsonConvert.DeserializeObject(json);

But I don't have an access to keys.

I'm not trying to deserialize into strongly-typed .net objects.

Upvotes: 0

Views: 103

Answers (1)

Andrii Litvinov
Andrii Litvinov

Reputation: 13192

You can use JObject.Parse method and iterate through KeyValuePair of JObject:

var jObject = JObject.Parse(json);

foreach (KeyValuePair<string, JToken> kvp in jObject)
{
    // Your code.
}

Upvotes: 0

Related Questions