c# - Converting JSON to XML -
i trying convert json output xml. unfortunately error:
json root object has multiple properties. root object must have single property in order create valid xml document. consider specifing deserializerootelementname.
this 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) httpwebrequest; using (httpwebresponse response = request.getresponse() httpwebresponse) { streamreader reader = new streamreader(response.getresponsestream()); jsonoutput = reader.readtoend(); console.writeline("this json output: " + jsonoutput); } xmldocument doc = (xmldocument)jsonconvert.deserializexmlnode(jsonoutput); console.writeline(doc); and json output:
{"id":"108013515952807","posts":{"data":[{"id":"108013515952807_470186843068804","created_time":"2013-05-14t20:43:28+0000"},{"message":"tekst","id":"108013515952807_470178529736302","created_time":"2013-05-14t20:22:07+0000"} how can solve problem?
despite fact json provided in question not complete, have multiple properties @ top level indicated exception. have define root valid xml:
var doc = jsonconvert.deserializexmlnode(jsonoutput, "root"); edit: in order print out xml indentation can use xdocument class system.xml.linq namespace: xdocument.parse(doc.innerxml).
Comments
Post a Comment