我根本没有使用JSON的经验,但遗憾的是我有一个向我返回数据的web服务。我需要将数据从JSON格式化为XML,以便我可以在这里导入我们自己的系统。
我以这种格式从Web服务接收数据:
{
"httpStatusCode": 200,
"messages": [],
"succesfulResponses": [
{
"position": 0,
"response": {
"dln": "AAAPY459037VB9SV",
"dvlaServiceVersion": "1",
"hubServiceVersion": "1.0.0.0",
"dvlaProcessingDate": "2014-12-22T14:03:43.557Z",
"hubProcessingDate": "2015-05-29T16:50:51.4364004+01:00",
"licence": {
"status": "FC",
"validFrom": "1986-01-22",
"validTo": "2017-09-02",
"directiveIndicator": 0,
"entitlements": [
{
"code": "A",
"validFrom": null,
"validTo": null,
"priorTo": false,
"type": "F",
"restrictions": []
}
],
"endorsements": []
},
"httpStatusCode": 200,
}
"messages": []
}
],
"errorResponses": []
}
我尝试使用Newtonsoft JSON.NET程序使用以下内容:
Dim doc As XmlDocument = DirectCast(JsonConvert.DeserializeXmlNode(sAnswer, "root"), XmlDocument)
不幸的是它返回了这个:
2000AAAPY459037VB9SV11.0.0.02014-12-22T14:03:43.557Z2015-05-29T16:59:08.6833762 + 01:00FC1986-01-222017-09-020AfalseF200
对我来说根本没用,我需要它来格式化XML完成节点名称/元素,以便我可以正确导入它,是否有人能指出我正确的方向?
干杯,
Ĵ
答案 0 :(得分:0)
管理以正确地将JSON格式化为XML。我将以下内容添加到我返回的JSON字符串中:
jSON = "{" & vbCr & vbLf & " '?xml': {" & vbCr & vbLf & " '@version': '1.0'," & vbCr & vbLf & " '@standalone': 'no'" & vbCr & vbLf & " }," & vbCr & vbLf & " 'root': " + sAnswer
然后指定通过' root'反序列化。