Use JSON. stringify () to generate a JSON string in beautiful format, json. stringifyjson
Clever UseJSON. stringify ()
Generate a JSON string in beautiful format
Processing XML using JavaScript is basically a cup of cake, which is also why JSON is widely used in program development. I have written a JavaScript function to convert XML into JSON ~ Duang ~ Duang ~ The pain point is that you want to die. If you want to convert an existing object to a JSON string, you can useJSON. stringify (obj)
Function. You may have used this function (not supported in IE6 or IE7 ). However, you may not know that you can use Parameter Control to generate a beautiful JSON format during conversion!
In fact, it is very simple.JSON. stringify
The third parameter of the function is used to specify the number of indented spaces:
// For example, an object is constructed literally. // in actual use, it is usually a POJO, or a value object such as VO var myObject = {"myProp ": "myValue", "subObj": {"prop": "value" }}; // format var formattedStr = JSON. stringify (myObject, null, 2 );
The generated string is as follows:
{"MyProp": "myValue", "subObj": {"prop": "value "}}
Original article: Indent JSON with JavaScript
Original Article Date: January 1, March 02, 2015
Translated on: February 1, March 09, 2015
Iron anchor http://blog.csdn.net/renfufei