Click here to Skip to main content
15,905,912 members
Please Sign up or sign in to vote.
3.00/5 (2 votes)
See more:
Hello Friend I am working on a JSON API and the output is something like this

"rank_name":"STAFF SERGEANT I",


But can anyone tell me how to manage each value in each label and how to do it?
Prasad Khandekar 30-May-13 11:28am    
What you want to do?
ToxicF3AR 30-May-13 11:32am    
Like in lable 1 it will show the name
and in label 2 it will show the rank
like this can we do it and is it possible ?
Prasad Khandekar 30-May-13 12:17pm    
You can use a JSON Library such as DynamicJson or JSON.Toolkit to achieve this. Basically by using these libraries you will get a reference to dynamic JSON Object and then from your code behind you can extract individual named items and assign those to your controls.
ToxicF3AR 30-May-13 13:17pm    
Any Example will be better for me
Sergey Alexandrovich Kryukov 30-May-13 12:20pm    
And what do you mean by "VB", exactly?

You ca read the json using jQuery and dynamically create labels for that.

See the DEMO - [DEMO] Working With JSON API[^].
Share this answer
Sergey Alexandrovich Kryukov 30-May-13 15:17pm    
Nice, a 5.
Thanks Sergey Alexandrovich Kryukov... :)
Thanks you guys but I have fixed it

Imports System.Net
Imports System.IO

Module Module1

    Sub Main()

        Console.WriteLine("I love Qmz_")
        Console.WriteLine("Press any key to start")
        Console.WriteLine("Checking... Please wait.")
        Dim url As String = "your api link here"
        Dim json As String = String.Empty

        Using client As New WebClient
                json = client.DownloadString(url)
            Catch ex As Exception
                Exit Sub
            End Try
        End Using

        json = json.Replace(vbLf.ToCharArray, "")
        json = json.Replace(Chr(34), "")

        Dim pos As Integer = InStr(json, "players")

        json = json.Substring(pos - 1, Len(json) - pos)
        pos = json.IndexOf("}")
        json = json.Substring(0, pos)

        Dim jsonArray() As String = json.Split(",".ToCharArray)
        Dim temp() As String

        For i As Integer = 0 To jsonArray.GetUpperBound(0)

            temp = jsonArray(i).Split(":".ToCharArray)

            If jsonArray(i).IndexOf("players") > -1 Then
                Console.WriteLine("Players: " & temp(1).Trim)
            ElseIf jsonArray(i).IndexOf("name") > -1 Then
                Console.WriteLine("name: " & temp(1).Trim())
            ElseIf jsonArray(i).IndexOf("rank") > -1 Then
                Console.WriteLine("rank: " & temp(1).Trim())
            ElseIf jsonArray(i).IndexOf("rank_name") > -1 Then
                Console.WriteLine("rank name: " & temp(1).Trim())
            ElseIf jsonArray(i).IndexOf("veteran") > -1 Then
                Console.WriteLine("veteran: " & temp(1).Trim)
            ElseIf jsonArray(i).IndexOf("score") > -1 Then
                Console.WriteLine("score: " & temp(1).Trim)
            ElseIf jsonArray(i).IndexOf("level") > -1 Then
                Console.WriteLine("level: " & temp(1).Trim)
            ElseIf jsonArray(i).IndexOf("kills") > -1 Then
                Console.WriteLine("kills: " & temp(1).Trim)
            ElseIf jsonArray(i).IndexOf("deaths") > -1 Then
                Console.WriteLine("deaths: " & temp(1).Trim)
            ElseIf jsonArray(i).IndexOf("time") > -1 Then
                Console.WriteLine("time: " & temp(1).Trim)
            ElseIf jsonArray(i).IndexOf("elo") > -1 Then
                Console.WriteLine("elo: " & temp(1).Trim)
            ElseIf jsonArray(i).IndexOf("form") > -1 Then
                Console.WriteLine("form: " & temp(1).Trim)
            ElseIf jsonArray(i).IndexOf("date_lastupdate") > -1 Then
                Console.WriteLine("last update date: " & temp(1).Trim)
            ElseIf jsonArray(i).IndexOf("count_update") > -1 Then
                Console.WriteLine("count update: " & temp(1).Trim)
            ElseIf jsonArray(i).IndexOf("general") > -1 Then
                Console.WriteLine("general: " & temp(1).Trim)
            ElseIf jsonArray(i).IndexOf("requested") > -1 Then
                Console.WriteLine("requested: " & temp(1).Trim)
            ElseIf jsonArray(i).IndexOf("found") > -1 Then
                Console.WriteLine("found: " & temp(1).Trim)

            End If

            Erase temp


        Erase jsonArray
        Console.WriteLine("Done !")
    End Sub

End Module
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900