-2

I have no experience with JSON at all, but I unfortunately have a webservice that returns data to me. I need to format the data from JSON into XML so that I can import into our own system here.

I receive the data from the Web Service in this format:

{
"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": []
 }

I tried to use the following using the Newtonsoft JSON.NET Program:

 Dim doc As XmlDocument = DirectCast(JsonConvert.DeserializeXmlNode(sAnswer, "root"), XmlDocument)

Unfortunately it returned this:

2000AAAPY459037VB9SV11.0.0.02014-12-22T14:03:43.557Z2015-05-29T16:59:08.6833762+01:00FC1986-01-222017-09-020AfalseF200

Which is of no use to me at all, I need it to format the XML complete the node name / elements so that I can import this correctly, is anyone able to point me in the right direction?

Cheers,

J

Lynchie
  • 1,077
  • 2
  • 20
  • 36
  • the json string represents serialized data, you cant just cast it to XML. also, be sure you copied/pasted all the json data - as posted it is not valid (see jsonlint.com) – Ňɏssa Pøngjǣrdenlarp May 29 '15 at 17:30
  • If you haven't done so already, I would check out some of the responses to this [earlier question](http://stackoverflow.com/questions/814001/convert-json-string-to-xml-or-xml-to-json-string) – ChicagoMike May 29 '15 at 17:50
  • Hi @Plutonix that is exactly the full code, so the returned data cannot be valid. I was told elsewhere the problem is there is no root element to the JSON. – Lynchie May 30 '15 at 13:47
  • Sorry, but nothing likes that json string: all three online parser tools say it is invalid and VS agrees (Edit - Paste Special - Paste as Json classes). You arent going to get far with it. – Ňɏssa Pøngjǣrdenlarp May 30 '15 at 13:50
  • Hi @Plutonix well unfortunately this is how it is returned by the MIB (Motor Insurance Bureau) who in the UK (I don't where you are based) are responsible for the Insurance Database of the whole country, Its highly unlikely they are going to change the code for little old me, so I'll have to work with what I have got, which is this :/ – Lynchie Jun 01 '15 at 08:04

1 Answers1

0

Managed to format the JSON to XML correctly. I added the following to my returned JSON String:

jSON = "{" & vbCr & vbLf & "  '?xml': {" & vbCr & vbLf & "    '@version': '1.0'," & vbCr & vbLf & "    '@standalone': 'no'" & vbCr & vbLf & "  }," & vbCr & vbLf & "  'root': " + sAnswer

Then specified to deserialize by 'root'

Lynchie
  • 1,077
  • 2
  • 20
  • 36