Graph The appearance of a value in a cycle

I am reading a Json array that returns Dates.

What I want to do is loop through the Json array, storing the dates, and counting the number of times each date has occurred.

       Using client As New WebClient
            Dim feedResponse As String = client.DownloadString(Url)
            Dim jsonObject As Object = JSONHelper.Deserialize(feedResponse)
            Dim feedArray As JArray = JSONHelper.readJSonArray(jsonObject, "data")

                For i = 0 To feedArray.Count - 1
                    Dim feedDetailsObject As Object = feedArray.ElementAt(i)
                    Dim feeddate = JSONHelper.readJSonElement(feedDetailsObject, "updated_time").ToShortDateString
                Next

            End If
        End Using

      

I want to count how many times the "feeddate" value occurs.

What is the best way to count the same value in a loop?

+3


source to share


1 answer


You can use LINQ GroupBy

to count the number of times each value occurs updated_time

:



Dim groupedDates = feedArray.GroupBy(Function(x) JSONHelper.readJSonElement(x, "updated_time").ToShortDateString)
For Each group In groupedDates
    Dim feedDate = group.Key
    Dim numberOfOccurrence = group.Count()
Next

      

+2


source







All Articles