JSON string converted to JSON object
// jquery的方法var jsonObj = $.parseJSON(jsonStr)//js 的方法var jsonObj = JSON.parse(jsonStr)
JSON object converted to JSON string
//js方法var jsonStr1 = JSON.stringify(jsonObj)
For example
For example:
<script type="Text/javascript">var jsonstr=' [{' id ': ' The ', ' ' open ': false, ' pid ': ' 0 ', ' name ': ' A department '},{' ID ': ' A ', ' open ': false, ' pid ': ' 0 ', ' name ': ' A department '},{' ID ': ' 011 ', "Open": false, "pid": "},{", "name": "A department" "id": "The", "open": false, "pid": "0", "name": "A department"},{"id": "", "open": false, "pid": "0", "name": "A Department"}, {"id": "", "" open ": false," pid ":" 0 "," name ":" A Department "}, {" id ":" "," "open": false, "pid": "0", " Name ":" A Department "}] '; //var jsonobj = $.parsejson (JSONSTR); var jsonobj = JSON. Parse (JSONSTR) console. Log (jsonobj) var jsonStr1 = JSON. Stringify (jsonobj) console. Log (jsonStr1+"jsonStr1") </script>
JSON Object Conversion Array
<script type="Text/javascript">var jsonstr=' [{' id ': ' The ', ' ' open ': false, ' pid ': ' 0 ', ' name ': ' A department '},{' ID ': ' A ', ' open ': false, ' pid ': ' 0 ', ' name ': ' A department '},{' ID ': ' 011 ', "Open": false, "pid": "},{", "name": "A department" "id": "The", "open": false, "pid": "0", "name": "A department"},{"id": "", "open": false, "pid": "0", "name": "A Department"}, {"id": "", "" open ": false," pid ":" 0 "," name ":" A Department "}, {" id ":" "," "open": false, "pid": "0", " Name ":" A Department "}] ';var jsonobj = $.parsejson (JSONSTR);var jsonobj=Json.Parse (JSONSTR)Console.Log (Jsonobj)var jsonStr1=Json.Stringify (Jsonobj)Console.log (Jsonstr1+ "JSONSTR1") var Jsonarr = []for (var I =0 ;i < jsonobj. Length;i++) {jsonarr[i] = jsonobj[i] } console. Log (typeof (Jsonarr)) </script
A JSON string, a JSON object, a conversion between arrays of three