Convert JS object to JSON string

后端 未结 27 2906
庸人自扰
庸人自扰 2020-11-22 00:43

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:

27条回答
  •  情话喂你
    2020-11-22 01:49

    You can use JSON.stringify() method to convert JSON object to String.

    var j={"name":"binchen"};
    JSON.stringify(j)
    

    For reverse process, you can use JSON.parse() method to convert JSON String to JSON Object.

提交回复
热议问题