Vb.net 如何在VB中定制HTTP JSON POST请求格式
这是最终结果{“recordType”:“b”,“recordNumber”:1550316,“pickupLocation”:“de”} InputJson=“{”“记录类型”“:”“b”“记录编号”“:”“1550316”“pickupLocation”“:”“de”“}” 返回=“httpStatus”:400, “名称”:“无效的JSON”, “说明”:“JSON对象缺少字段或字段具有无效数据” 我需要帮助正确格式化我的post请求,使其看起来像以下内容。请注意,recordnumber值没有引号。->Vb.net 如何在VB中定制HTTP JSON POST请求格式,vb.net,linq,post,json.net,Vb.net,Linq,Post,Json.net,这是最终结果{“recordType”:“b”,“recordNumber”:1550316,“pickupLocation”:“de”} InputJson=“{”“记录类型”“:”“b”“记录编号”“:”“1550316”“pickupLocation”“:”“de”“}” 返回=“httpStatus”:400, “名称”:“无效的JSON”, “说明”:“JSON对象缺少字段或字段具有无效数据” 我需要帮助正确格式化我的post请求,使其看起来像以下内容。请注意,recordnumber
{"recordType": "b", "recordNumber": 1550316, "pickupLocation": "de"}
TY:)我猜recordId是一种字符串类型 选项1:创建一个具体的类并远离匿名类型
Public Class YourClass
Public Property recordType As String
Public Property recordNumber As Integer
Public Property pickupLocation As String
End Class
Dim input As Object = New With {
.recordType = "b",
.recordNumber = System.Convert.ToInt32(recordId),
.pickupLocation = "de"
}
选项2:如果您确定这是一个整数,那么在初始化匿名类型时只需将其转换为整数即可
Public Class YourClass
Public Property recordType As String
Public Property recordNumber As Integer
Public Property pickupLocation As String
End Class
Dim input As Object = New With {
.recordType = "b",
.recordNumber = System.Convert.ToInt32(recordId),
.pickupLocation = "de"
}
感谢您回答N0Alias。选项2:设法除去recordNumber->“{”“recordType”“:”“b”“recordNumber”“:1550316”“pickupLocation”“:”“de”“}”周围的引号。你知道如何修复{}外部的引号并用{}替换内部的双引号吗