在asp.net应用程序中接收数据
我向一个api发出http请求,该api反过来向我的asp.net应用程序发送一些响应 发送的数据格式为在asp.net应用程序中接收数据,asp.net,json,http,Asp.net,Json,Http,我向一个api发出http请求,该api反过来向我的asp.net应用程序发送一些响应 发送的数据格式为 { "deliveryInfoNotification": { "deliveryInfo": { "address": "14075550100", "code": "0", "createdDateTime": "2011-05-12T00:55:25.313Z", "
{
"deliveryInfoNotification": {
"deliveryInfo": {
"address": "14075550100",
"code": "0",
"createdDateTime": "2011-05-12T00:55:25.313Z",
"deliveryStatus": "DeliveredToNetwork",
"direction": "outbound",
"message": "Hello world",
"messageId": "3e5caf2782cb2eb310878b03efec5083",
"parts": "1",
"senderAddress": "16575550100",
"sentDateTime": "2011-05-12T00:55:34.359Z"
}
}
}
在asp.net应用程序中接收到这些数据后,如何通过它接收和解析这些数据?要在asp.net中处理JSON,可以使用
Web.Script.Serialization.JavaScriptSerializer
(添加对System.Web.Extensions
的引用)。将.DeserializeObject()
返回的对象转换为通用.Dictionary
以使用它
Dim json As String=String.Concat(
"{",
“deliveryInfoNotification”“:{”,
“deliveryInfo:{”,
“地址”:“14075550100”,
“代码”:“0”,
“createdDateTime:”2011-05-12T00:55:25.313Z“,
“deliveryStatus”:“DeliveredNetwork”,
“方向”:“出站”,
“消息”:“你好,世界”,
“消息ID”:“3e5caf2782cb2eb310878b03efec5083”,
“部分”:“1”,
“发件人地址”:“16575550100”,
“sentDateTime:”2011-05-12T00:55:34.359Z“,
"}",
"}",
"}")
Dim序列化程序作为新的Web.Script.Serialization.JavaScriptSerializer,
jsonObject作为System.Collections.Generic.Dictionary(字符串、对象)=
DirectCast(serializer.DeserializeObject(json)、System.Collections.Generic.Dictionary(字符串、对象))
如果jsonObject.Count>0_
AndAlso jsonObject.ContainsKey(“deliveryInfoNotification”)_
AndAlso jsonObject(“deliveryInfoNotification”)。ContainsKey(“deliveryInfo”)则
Dim deliveryInfo作为System.Collections.Generic.Dictionary(字符串、对象的形式)=jsonObject(“deliveryInfoNotification”)(“deliveryInfo”),
地址为字符串=deliveryInfo(“地址”),
代码为字符串=deliveryInfo(“代码”),
createdDateTime作为字符串=deliveryInfo(“createdDateTime”),
deliveryStatus作为字符串=deliveryInfo(“deliveryStatus”),
方向为字符串=deliveryInfo(“方向”),
消息为字符串=deliveryInfo(“消息”),
messageId为String=deliveryInfo(“messageId”),
零件作为字符串=交货信息(“零件”),
senderAddress As String=deliveryInfo(“senderAddress”),
sentDateTime作为字符串=deliveryInfo(“sentDateTime”)
如果结束