Convert JS object to JSON string

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

    In angularJS

    angular.toJson(obj, pretty);
    

    obj: Input to be serialized into JSON.

    pretty(optional):
    If set to true, the JSON output will contain newlines and whitespace. If set to an integer, the JSON output will contain that many spaces per indentation.

    (default: 2)

提交回复
热议问题