Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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);
like image 679
hal Avatar asked Mar 25 '26 13:03

hal


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)
like image 182
Jawad Avatar answered Mar 27 '26 01:03

Jawad



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!