Convert JS object to JSON string

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

    use JSON.stringify(param1, param2, param3);

    What is: -

    param1 --> value to convert to JSON

    param2 --> function to stringify in your own way. Alternatively, it serves as a white list for which objects need to be included in the final JSON.

    param3 --> A Number data type which indicates number of whitespaces to add. Max allowed are 10.

提交回复
热议问题