banner
Jan 14, 2020
10 Views

Find a Specific Object in JSON Array

Written by
banner

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:

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

 

 

Article Tags:
Article Categories:
JSON · VB.NET
banner
    https://mfaisal.com

    Seseorang yang selalu tertarik dengan Computer Programming, Photoshop, Web Design, Motivasi, Wordpress dan Internet. Silahkang lingkari saya di Google+ : Faisal dan Facebook. Atau follow juga di Twitter

    Leave a Reply

    Your email address will not be published. Required fields are marked *