How to parse json and read in vb.net

后端 未结 4 1136
独厮守ぢ
独厮守ぢ 2020-11-29 11:23

I have this code in my project:

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

request = DirectCast(Web         


        
4条回答
  •  爱一瞬间的悲伤
    2020-11-29 11:44

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

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

    Sorry if my reply was late. I hope my answer can help someone who's still confused. So what you do was get the response and read the JSON.

    After you do ReadToEnd():

    Dim xr As XmlReader = XmlReader.Create(New StringReader(rawresp))
    Dim doc As XmlDocument = New XmlDocument()
    doc.LoadXml(rawresp)
    

    Then What you need to do is to read the data from the response. you do like this:

    Dim res As String = JsonConvert.SerializeXmlNode(doc)
    Dim ThisToken As JObject = Newtonsoft.Json.JsonConvert.DeserializeObject(Of JObject)(res)
    Dim response As String = ThisToken("response").ToString()
    Dim ThisData As JObject = Newtonsoft.Json.JsonConvert.DeserializeObject(Of JObject)(response)
    

    After that yo can get the data from the response and convert it into string

    Dim idx As String = ThisData("id").ToString()
    
    // the value of idx will be: 174543706
    

    Then last you can put it into Texbox3.Text.

提交回复
热议问题