Find a Specific Object in JSON Array

I have json file that has

[{"a":"Value","b":"Value"},{"a":"Value1","b":"Value1"}]

I want to find a specific object in the JSON array where the a property has the value Value1. In that case I can use Json.Net’s LINQ-to-JSON API (JObjects, etc.) to find it like this:

Read More
Dim json As String = _
    "[{""a"":""Value"",""b"":""Value""},{""a"":""Value1"",""b"":""Value1""}]"

Dim array As JArray = JArray.Parse(json)

Dim obj As JObject = _ 
    array.FirstOrDefault(Function(jo As JObject) jo("a").ToString() = "Value1")

If obj Is Nothing Then
    Console.WriteLine("Not found")
Else
    Console.WriteLine("a: " & obj("a").ToString())
    Console.WriteLine("b: " & obj("b").ToString())
End If

 

 

Related posts