1

I am tring a xml data convert to json. but I got a issue.

        string xml = "<Test><Name>Test class</Name><X>100</X><Y>200</Y></Test>";

        XmlDocument doc = new XmlDocument();
        doc.LoadXml(xml);

        return    Newtonsoft.Json.JsonConvert.SerializeXmlNode(doc);

when display datavisualizer

{"Test":{"Name":"Test class","X":"100","Y":"200"}}

but page return it

"{\"Test\":{\"Name\":\"Test class\",\"X\":\"100\",\"Y\":\"200\"}}"

it not a valid json.

how to format it?

2
  • are you using ajax to get this data... Commented Aug 8, 2013 at 12:24
  • 1
    Also, is this string as you receive it (and save it) from a client app, or in the debugger? That escaping of the quotes looks like a debugger artifact... Commented Aug 8, 2013 at 12:29

1 Answer 1

1

What actually happening is you already passing json string to the client, so at client if you give dataType as "json" it will again serialize string and will get above result.

fact is this is not invalid json actually, you need it to parse to get json object

at client side...using javascript

var jsonObject = JSON.parse("{\"Test\":{\"Name\":\"Test class\",\"X\":\"100\",\"Y\":\"200\"}}");
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you bro.. I am new in JQuery+JSON. my mistake.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.