I'm a beginner in Javascript, so I'm sorry for the following joke.
Sometimes, after obtaining the JSON data, we can only deduce it in the background. if the background is not processed by us, how can we get the format:
// OBJ function jsontostring (OBJ) {var STR = ""; var depth = 0; function jsonparsestring (OBJ) {for (var p in OBJ) {If (object. prototype. tostring. apply (OBJ [p]) = "[object array]") {STR + = P + ":" + "\ n"; var length = OBJ [p]. length; For (VAR I = 0; I <length; I ++) {depth ++; jsonparsestring (OBJ [p] [I]);} else {var con = ""; for (var j = 0; j <depth; j ++) con + = ""; STR + = con + P + "=" + OBJ [p] + "\ n" ;}} depth -- ;} jsonparsestring (OBJ); Return STR ;}
The data is transmitted in JSON format. first, I would like to use a recursive function. however, it is found that the result is incorrect (if there is an array in JSON, the analysis results in the array will not be obtained) mainly because the string in Javascript is a value transfer.
So I want to use global variables. But this function is called for other purposes. It is impossible to write a global variable.
And then use the closure of JavaScript to achieve the corresponding effect without using global variables. This is also true for deep control.
There is no specific test for deep control. If an array exists in the array, or the array cannot be correctly displayed (This test is not performed due to the time relationship)
The resolution result is as follows:
Some people may see it. This is the JSON format required by jqgrid.