gpt4 book ai didi

json - 如何解析json并在vb.net中读取

转载 作者:行者123 更新时间:2023-12-04 01:50:52 24 4
gpt4 key购买 nike

我的项目中有以下代码:

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


和TextBox2正确获取JSON代码。

这是我的JSON代码示例:

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


我的问题:

如何从JSON代码(“ id”)中获取174543706到TextBox3.Text中?

最佳答案

您可以使用JavaScriptSerializer中的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

关于json - 如何解析json并在vb.net中读取,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38943260/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com