I can serialize XML to a JSON string like this:
var xml = new XmlDocument();
xml.LoadXml("<person><name>John</name></person>");
string jsonString = Newtonsoft.Json.JsonConvert.SerializeXmlNode(xml, Newtonsoft.Json.Formatting.None);
Response.ContentType = "application/json";
Response.Write(Newtonsoft.Json.JsonConvert.SerializeObject(jsonString));
That would give me:
"{\"person\开发者_运维问答":{\"name\":\"John\"}}"
But how can I serialize it to a JSON object? Like this:
{"person":{"name":"John"}}
Sometimes we just want to make it harder than it is ...
var xml = new XmlDocument();
xml.LoadXml("<person><name>John</name></person>");
Response.ContentType = "application/json";
Response.Write(Newtonsoft.Json.JsonConvert.SerializeObject(xml));
What I did wrong was to serialize the XML into a string and then serialize it again.
when you will access data then / automatically does not show . I am accessing in HTML5 help of AJAX post . Result is showing
in C# result is showing that "{\"person\":{\"name\":\"John\"}}"
But in HTML5 , it is working fine {"person":{"name":"John"}}
精彩评论