A detailed description of JSON arrays and JSON objects and how to use $.post

Source: Internet
Author: User
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

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.