In this article we mainly share with you the detailed explanation of json arrays and json objects and the method of using $.post. We hope it can help you. First, let’s take a look at a piece of code:
var jsonarray = eval('('+"[]"+')'); jsonarray.push( { "openid":"1", "operate_type":"sbbb" } );
First of all, we know that the outermost layer of the array is [], and the outermost layer of the object is {}.
The above code first creates a json array. There must be two brackets enclosed by single quotes in the eval function. Please refer to Baidu for the specific reason. And because the outermost layer of thearray is [], the first line of code is "[]". In this way, the variable jsonarray can use the functions or operations of the array. Such as push. You only need to provide the correct string format of the json data in the push parameter, and the function will automatically convert it into array elements.
var jsonObject = eval('('+"{}"+')'); jsonObject.name = "zhang"; jsonObject.old = "18"; jsonObject.person = [{"name":"taylor","old":"22"},{"name":"taylor","old":"18"}]; console.log(jsonObject);
To create a json object,Because the outermost layer of the objectis {}, so the first line It's "{}" in the code.In this way, the variable jsonObject can use the object's functions or operations.To set the key and value, just follow the second and third lines of code. If the value of a key is an array, then just give the correct string format of thejson array.
##$.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); });
Related recommendations:
$.post submits data and returns data in json format method example
javascript jQuery $.post $. Ajax usage
Simple example of $.post() method in jquery
The above is the detailed content of Detailed explanation of json array and json object and how to use $.post. For more information, please follow other related articles on the PHP Chinese website!