Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I have this code in my project:

Dim request As HttpWebRequest
Dim response As HttpWebResponse = Nothing
Dim reader As StreamReader

request = DirectCast(WebRequest.Create("https://url.to.my.json"), HttpWebRequest)

response = DirectCast(request.GetResponse(), HttpWebResponse)
reader = New StreamReader(response.GetResponseStream())

Dim rawresp As String
rawresp = reader.ReadToEnd()
textbox2.text = rawresp

and TextBox2 gets the JSON code correctly.

and this is my JSON code example:

{
  "id":174543706,
  "first_name":"Hamed",
  "last_name":"Ap",
  "username":"hamed_ap",
  "type":"private"
}

My question:

How to get 174543706 from JSON code ("id") into TextBox3.Text???

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
186 views
Welcome To Ask or Share your Answers For Others

1 Answer

You could use JavaScriptSerializer which is in System.Web.Script.Serialization.

Imports System.Web.Script.Serialization

Module Module1
    Sub Main()

        Dim s As String

        Try
            Dim rawresp As String = "{""id"":174543706,""first_name"":""Hamed"",""last_name"":""Ap"",""username"":""hamed_ap"",""type"":""private""}"

            Dim jss As New JavaScriptSerializer()
            Dim dict As Dictionary(Of String, String) = jss.Deserialize(Of Dictionary(Of String, String))(rawresp)

            s = dict("id")
        Catch ex As Exception

        End Try

    End Sub

End Module

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...