VB.NET如何读取http上的json响应

人气:580 发布:2022-10-16 标签: json vb.net

问题描述

大家好,我需要您的帮助,我想在http响应上读取json,这是响应

Hello Guys I need your help I want to read a json on a http response this is the reponse

{"response":{"session_id":"lku1ui1dr3ff4p2q4agmcd0jd3","expire_date":1527950247,"traffic_left":"13032101083573"},"response_status":200,"response_details":null}

{"response":{"session_id":"lku1ui1dr3ff4p2q4agmcd0jd3","expire_date":1527950247,"traffic_left":"13032101083573"},"response_status":200,"response_details":null}

这是帖子数据及其示例数据

This is the post data its a example data

POST示例/api/用户/登录HTTP/1.1

POST example/api/user/login HTTP/1.1

接受:/

用户代理:Mozilla/5.0(Windows; U; Windows NT 5.1; zh-CN) AppleWebKit/522.11.3(KHTML,例如Gecko)版本/3.0 Safari/522.11.3

User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en) AppleWebKit/522.11.3 (KHTML, like Gecko) Version/3.0 Safari/522.11.3

主机:example.net

Host: example.net

编译指示:无缓存

连接:保持活动状态

内容类型:application/x-www-form-urlencoded内容长度:46

Content-Type: application/x-www-form-urlencoded Content-Length: 46

username = example& password = 1234456

username=example&password=1234456

我想阅读"expire_date":,如果它存在则它将 昏暗expiredate作为字符串

I want to read the "expire_date":, if it exists then it will Dim expiredate as string

Public Sub method_5()
        Dim proxyAddress As String = Me.string_1(Me.random_0.[Next](0, Me.int_1)),
        While Me.queue_0.Count > 0
            Dim obj As Object = Me.object_0
            Dim flag As Boolean = False
            Dim obj2 As Object
            Dim text As String
            Try
                Dim expr_29 As Object = obj
                obj2 = expr_29
                Monitor.Enter(expr_29, flag)
                Try
                    text = Me.queue_0.Peek().ToString().TrimEnd(New Char() {vbCr}).Trim()
                    Me.queue_0.Dequeue()
                Catch ex As Exception

                End Try

            Finally
                If flag Then
#Disable Warning BC42104 ' Variable is used before it has been assigned a value
                    Monitor.[Exit](obj2)
#Enable Warning BC42104 ' Variable is used before it has been assigned a value
                End If
            End Try
            Dim array As String() = text.Split(New Char() {":"})
            Try
                Using httpRequest As HttpRequest = New HttpRequest()
                    httpRequest.Proxy = ProxyClient.Parse(Me.proxyType_0, proxyAddress)
                    Dim cookies As CookieDictionary = New CookieDictionary(False)
                    httpRequest.Cookies = cookies
                    httpRequest.IgnoreProtocolErrors = True
                    httpRequest.ConnectTimeout = 25000
                    httpRequest.AllowAutoRedirect = True
                    httpRequest.KeepAlive = True
                    httpRequest.UserAgent = Http.ChromeUserAgent()
                    httpRequest.AddParam("username", array(0))
                    httpRequest.AddParam("password", array(1))
                    Dim text2 As String = httpRequest.Post("<website>").ToString()
                    If text2.Contains("") Then
                    End If
                    obj = Me.object_0
                    Dim flag2 As Boolean = False
                    Try
                        Dim expr_222 As Object = obj
                        obj2 = expr_222
                        Monitor.Enter(expr_222, flag2)
#Disable Warning BC42025 ' Access of shared member, constant member, enum member or nested type through an instance
                        array.Resize(Of String)(Me.string_2, Me.int_2 + 1)
#Enable Warning BC42025 ' Access of shared member, constant member, enum member or nested type through an instance
#Disable Warning BC42104 ' Variable is used before it has been assigned a value
                            Me.string_2(Me.int_2) = +text + "|Subscription: "
#Enable Warning BC42104 ' Variable is used before it has been assigned a value
                            Me.int_2 += 1
                        Me.int_5 += 1
                        Me.int_6 -= 1
                        Continue While
                    Finally
                        If flag2 Then
                            Monitor.[Exit](obj2)
                        End If
                    End Try
                    obj = Me.object_0
                    Dim flag3 As Boolean = False
                    Try
                        Dim expr_29E As Object = obj
                        obj2 = expr_29E
                        Monitor.Enter(expr_29E, flag3)
                        Me.int_3 += 1
                    Finally
                        If flag3 Then
                            Monitor.[Exit](obj2)
                        End If
                    End Try
                    Me.int_5 += 1
                    Me.int_6 -= 1
                End Using
            Catch
                Me.int_7 += 1
                Me.queue_0.Enqueue(text)
                proxyAddress = Me.string_1(Me.random_0.[Next](0, Me.int_1))
            End Try
        End While
        If Me.int_5 = Me.int_0 Then
            Me.method_6()
        End If
    End Sub

只是不要介意也不要介意错误会导致其部分代码不完整

just don't mind the don't mind too the errors cause its not a full code its part of it

推荐答案

我相信这与您要查找的内容相似,

I believe this is similar to what you're looking for, :

Dim req As HttpWebRequest = WebRequest.Create("www.SomeURL.com/?username=somevalue&password=somevalue")
Dim resp As HttpWebResponse = req.GetResponse()

Dim enc As Encoding = System.Text.Encoding.GetEncoding(1252)
Dim loResponseStream As StreamReader = New StreamReader(resp.GetResponseStream(), enc)
Dim Response As String = loResponseStream.ReadToEnd()
Dim jss As JavaScriptSerializer = New JavaScriptSerializer()
Dim dict As Object = jss.Deserialize(Of Dictionary(Of String, Object))(Response)
Dim expiredate As String = (dict("session_id")("expire_date")) 'You may need to play with this to get the value, wrote this off the top of my head ...
loResponseStream.Close()

617