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:
Just use JSON.stringify to do such conversion - however remember that fields which have undefined value will not be included into json
JSON.stringify
undefined
var j={"name":"binchen", "remember":undefined, "age": null }; var s=JSON.stringify(j); console.log(s);
The field remember 'disappear' from output json
remember