If I defined an object in JS with:
var j={\"name\":\"binchen\"};
How can I convert the object to JSON? The output string should be:
JSON.stringify
turns a Javascript object into JSON text and stores that JSON text in a string.
The conversion is an Object to String
JSON.parse
turns a string of JSON text into a Javascript object.
The conversion is a String to Object
var j={"name":"binchen"};
to make it a JSON String following could be used.
JSON.stringify({"key":"value"});
JSON.stringify({"name":"binchen"});
For more info you can refer to this link below.
https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify