Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JSON.Net get native type of value

Using JSON.Net, how do I get the native type of a value in a JSON file? Namely, I'm after simply if it's a string (value enclosed in quotations) or not.

var json = (JObject) JsonConvert.DeserializeObject(newVersion.JSON);
foreach (var data in json)
{
    if(data.value IS STRING){

    }
}
like image 754
Tom Gullen Avatar asked Feb 17 '15 14:02

Tom Gullen


1 Answers

You can simply check the Type property of each JToken in your list:

foreach (var data in json)
{
    if (data.Value.Type == JTokenType.String)
        // ...
    }
}

See JTokenType

like image 120
haim770 Avatar answered Oct 03 '22 06:10

haim770