Answered by:
how to convert xml to json in c#

Question
-
User-1738998028 posted
I have this follow xml
<?xml version="1.0" encoding="UTF-8"?>
<latestresult>
<latest>
<type>post</type>
<id>95</id>
<title>
</title>
<type>post</type>
<id>94</id>
<title>
</title>
</latest>
</latestresult>i tried to get json, i got only this, and not woking
{ "latest": [ { "type": "" } ] }
this is my c# code
XmlTextReader reader = new XmlTextReader(xmlPath + "latest.xml");
while (reader.Read())
{
switch (reader.NodeType)
{
case XmlNodeType.Element:
jsontext = new JObject(
new JProperty("latest",new JArray(
new JObject(
new JProperty("type", reader.Value)
)
))
);
break;
case XmlNodeType.Text :
jsontext = new JObject(
new JProperty("latest", new JArray(
new JObject(
new JProperty("type", (Object)reader.Value)
)
))
);
break;
default:
break;
}
}catch{}
Saturday, June 25, 2011 7:53 AM
Answers
-
User1509044783 posted
Hello.
You may try looking at Json.Net at http://james.newtonking.com/
For your reference, http://stackoverflow.com/questions/814001/json-net-convert-json-string-to-xml-or-xml-to-json-string
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Wednesday, June 29, 2011 12:31 AM
All replies
-
User-1367372477 posted
Hi,
you might try to looks at this below links.
http://www.phdcc.com/xml2json.htm
hope this will help you alot.
Regards,
Herman
Saturday, June 25, 2011 10:54 AM -
User527778624 posted
HI,
u can try this library to convert xml to json.
it's Json.Net
check it here:
http://json.codeplex.com/
Saturday, June 25, 2011 11:52 AM -
User-1738998028 posted
http://www.phdcc.com/xml2json.htm
I have tried this but not the way that i wanted.
i want pure xml to json. i might change some other way instead of using xml
thank you anyway.
Saturday, June 25, 2011 12:32 PM -
User1509044783 posted
Hello.
You may try looking at Json.Net at http://james.newtonking.com/
For your reference, http://stackoverflow.com/questions/814001/json-net-convert-json-string-to-xml-or-xml-to-json-string
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Wednesday, June 29, 2011 12:31 AM