码迷,mamicode.com
首页 > Windows程序 > 详细

VB 老旧版本维护系列---尴尬的webapi访问返回json对象

时间:2019-12-10 17:25:24      阅读:171      评论:0      收藏:0      [点我收藏+]

标签:false   utf-8   bapi   string   ali   serial   type   byte   获取   

尴尬的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

 

VB 老旧版本维护系列---尴尬的webapi访问返回json对象

标签:false   utf-8   bapi   string   ali   serial   type   byte   获取   

原文地址:https://www.cnblogs.com/bingshao/p/12017276.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!