Convert JS object to JSON string

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

    All current browsers have native JSON support built in. So as long as you're not dealing with prehistoric browsers like IE6/7 you can do it just as easily as that:

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

提交回复
热议问题