JSON Deserialize ( NewtonSoft JSON.NET) to XML Failure

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

Open in new window


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

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

Open in new window


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
Lynchie435Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Miguel OzSoftware EngineerCommented:
There is no root element in the posted JSON string, in fact there are multiple properties.
A possible solution is to add a root element as shown below:
string json = @"{
  '?xml': {
    '@version': '1.0',
    '@standalone': 'no'
  },
  'root': " + sAnswer;
XmlDocument doc = (XmlDocument)JsonConvert.DeserializeXmlNode(json);

Open in new window


For further info, check:
http://www.newtonsoft.com/json/help/html/ConvertingJSONandXML.htm

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Lynchie435Author Commented:
Thank you Miguel, worked a treat for me.

J
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
XML

From novice to tech pro — start learning today.