VB 老旧版本维护系列---尴尬的webapi访问返回json对象
阅读原文时间:2023年07月08日阅读:1

尴尬的webapi访问返回json对象

首先Imports Newtonsoft.Json

Imports MSXML2(Interop.MSXML2.dll)

Dim URLEncode As System.Text.Encoding = System.Text.Encoding.GetEncoding("utf-8")

'所需传递的json对象参数

Dim requestDataJson As String=requestDataJson = JsonConvert.SerializeObject("")

Dim responseText As String = ""

Dim postUrl As String = ""

Dim postdata() As System.Byte = URLEncode.GetBytes(requestDataJson)

Dim oXMLHttp2 As New XMLHTTP60()

oXMLHttp2.open("Post", postUrl, False)

oXMLHttp2.setRequestHeader("Content-Type", "text/json; charset=utf-8")

oXMLHttp2.setRequestHeader("Content-length", postdata.Length)

oXMLHttp2.setRequestHeader("Accept-Language", "zh-CN")

oXMLHttp2.send(requestDataJson)

'_获取返回结果,string类型_

responseText = oXMLHttp2.responseText

'去除转义符,及左右两边的双引号(尴尬所在点

responseText = responseText.Replace("\", "").Trim(Chr(34))

If responseText <> "" Then

result = JsonConvert.DeserializeObject(Of ResponseResult)(responseText)

End If

手机扫一扫

移动阅读更方便

阿里云服务器
腾讯云服务器
七牛云服务器