How do I check Json array if it contains specific value?

Viewed 560

How do I check Json array if it contains specific value?

This is code in which I load the data:

 dynamic d = JObject.Parse("{number:1000, str:'string', array: [1,2,3,4,5,6]}");

 Console.WriteLine(d.number);
 Console.WriteLine(d.str);
 Console.WriteLine(d.array.Count);
 //this does not work
 d.array.Contains(1);
1 Answers

You will need to use ToObject to convert the JArray to a list for you to use Contain method.,

d.array.ToObject<List<int>>().Contains(1)
Related