Home > DeveloperSection > Forums > Converting JSON to XML
Takeshi Okada
Takeshi Okada

Total Post:89

Posted on    May-16-2013 2:05 AM

 Facebook API Facebook API 

 1 Reply(s)
 3521  View(s)
Rate this:
Hi Expert! 

I trying to convert JSON output into XML. Unfortunately I get this error:

JSON root object has multiple properties. The root object must have a single property in order to create a valid XML document. Consider specifing a DeserializeRootElementName.

This is what I up to now created.

string url = string.Format("https://graph.facebook.com/{0}?fields=posts.fields(message)&access_token={1}", user_name, access_token);

  HttpWebRequest request = WebRequest.Create(url) as HttpWebRequest;

  using (HttpWebResponse response = request.GetResponse() as HttpWebResponse)
              StreamReader reader = new StreamReader(response.GetResponseStream());
              jsonOutput = reader.ReadToEnd();
              Console.WriteLine("THIS IS JSON OUTPUT: " + jsonOutput);
  XmlDocument doc = (XmlDocument)JsonConvert.DeserializeXmlNode(jsonOutput);
And this is my JSON output:


How can I solve this problem?

Thanks in advance! 


Total Post:604

Posted on    May-16-2013 8:07 AM

Hi Takeshi!

Despite the fact your JSON provided in the question is not complete, you have multiple properties at the top level as indicated by the exception. 

You have to define the root for it to get valid XML:

var doc = JsonConvert.DeserializeXmlNode(jsonOutput, "root");

Don't want to miss updates? Please click the below button!

Follow MindStick