This article we mainly share with you JSON array and JSON object in detail and use $.post method, hope to help everyone, first we look at a piece of code:
var Jsonarray = eval (' (' + ' [] ' + ') '); Jsonarray.push ({"OpenID": "1", "Operate_type": "SBBB"});
First we know that the outermost layer of the array is [], and the outermost layer of the object is {}.
The above code is the first to create a JSON array, where the Eval function must have two quotation marks wrapped in parentheses, for specific reasons please Baidu. And because the outermost part of the array is [], the first line of code is "[]". This allows the variable Jsonarray to use the function or operation of the array. such as push. In the push parameter, you only need to give the correct string format for the JSON data, and the function will automatically convert it to an array element.
var jsonobject = eval (' (' + ' + ' {} ' + ') '); Jsonobject.name = "Zhang"; jsonobject.old = "+"; Jsonobject.person = [{"Name": "Taylor", "old": "All"},{"name": "Taylor", " Old ":" 18 "}]; Console.log (Jsonobject);
To create a JSON object, because the outermost layer of the object is {}, the first line of code is "{}". This allows the variable jsonobject to use the object's function or operation. to set the key and value as the 23rd line of code. If the value of a key is an array, then the correct string format for the JSON array is given.
The $.post method in jquery
$.post ("{php echo web_url (' Management/management/set_admini ');}", {group_id:group_id, admini_to_set:jsonobject}, function (data) {alert (data);});
When the JSON array or JSON object is uploaded to the php background, in PHP with $admini_to_set = $_post [' Admini_to_set '] to pass the parameters taken out, found that: whether it is a JSON array or JSON object, as long as the above parameters are taken out, This parameter is bound to become a PHP array.
Related recommendations:
$.post submitting data and returning data method instances in JSON format
JavaScript jQuery $.post $.ajax usage
A simple example of the $.post () method in jquery