Convert JS object to JSON string

后端 未结 27 2515
庸人自扰
庸人自扰 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:31

    Use the stringify function

    var j = {
    "name":"binchen"
    };
    
    var j_json = JSON.stringify(j);
    
    console.log("j in json object format :", j_json);
    

    Happy coding!!!

提交回复
热议问题