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

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.