how to convert xml to json in c#
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{}
Read more here: Source link