varJSON ={name:"Task Name", Scorerule:"", Score:"",//If the rule expression is not empty, the evaluate by rule expression is selected by defaultUnique:1, StartTime:"2014-09-15 20:20:20", EndTime:"2014-10-15 20:20:20", Status:1, Istaks:0, Tradetype:1, Description:"Business description", codes: ["16", "6"],//the selected platformIDS: ["3"],//App Internal linksTest: {A:1, B: [1, 2, 3] }};varJson2 ={A:1, B:2, C: {A:1, B: {a:1, B: [1, 2]}, c: [1, 2]}, D: [1, 2, {a:1, B: {a:1}, C: [1, 2] }]};/** * Convert the JSON format object to a commit string format, filter out the function {a: {b:3}, B: [1], C: "D"}, A.b=3&b[0]=1&c=d * @param {object} data to go JSON Object * @param {string} prefix to be prefixed with * @return {string} string*/functionparamdata (data, prefix) {var_gettype =({}). toString, _paramarray=function(arr, prefix) {varresult =[], J= 0, Len=arr.length; for(; J < Len; J + +) { vardata =arr[j], type=_gettype.call (data), Subprefix= prefix + "[" + j + "]"; Result= Result.concat (_paramall (arr[j], prefix + "[" + j + "]")); } returnresult; }, _paramall=function(data, prefix) {varresult =[], type=_gettype.call (data); Switch(type) { Case"[Object Object]" : varSubprefix = prefix? Prefix + ".": "", I; for(IinchData) result = Result.concat (_paramall (Data[i], Subprefix +i)); Break; Case"[Object Array]": Result=Result.concat (_paramarray (data, prefix)); Break; Case"[Object String]" : Case"[Object number]": Result.push (prefix+ "=" +data); } returnresult; }; Prefix= Prefix | | ""; //if (prefix) {//prefix must end with. //prefix =/\.$/.test (prefix) prefix: (prefix + "."); //} else { //prefix = ""; // } return(function () { return_paramall (data, prefix); } ()). Join ("&"); }console.log (Paramdata (Json2,"Rule") ); Console.log (Paramdata (JSON,"rule"));
The JSON format object is converted into a b:3 string format, which filters out the function {a: {a}, B: [1], C: "D"}, A.b=3&b[0]=1&c=d