[Resolved]php How to parse such a JSON string

Source: Internet
Author: User
var xx = 'dfdf';var yy = 'kfdl';var zz = 'ijklk';instance:[{"instance_name":xx,"machine_belong":yy,"access_port":zz},{"instance_name":xx,"machine_belong":yy,"access_port":zz}]

How PHP is handled in the background

instance = [{"instance_name": 1, "Machine_belong": 2, "Access_port": 3},{"instance_name": 1, "Machine_belong": 2, "access _port ": 3}];

Use this to do the test, is the JSON write the wrong, My code JSON is stitching, splicing error

Reply content:

var xx = 'dfdf';var yy = 'kfdl';var zz = 'ijklk';instance:[{"instance_name":xx,"machine_belong":yy,"access_port":zz},{"instance_name":xx,"machine_belong":yy,"access_port":zz}]

How PHP is handled in the background

instance = [{"instance_name": 1, "Machine_belong": 2, "Access_port": 3},{"instance_name": 1, "Machine_belong": 2, "access _port ": 3}];

Use this to do the test, is the JSON write the wrong, My code JSON is stitching, splicing error

instance = [{"instance_name":xx,"machine_belong":yy,"access_port":zz},{"instance_name":xx,"machine_belong":yy,"access_port":zz}]// 对instance json序列化, 才可以进行数据传输instance = JSON.stringify(instance);

PHP parsing:

$instance = json_decode($_REQUEST['instance'], true);

Buxie

You should turn the object into a string character before sending it back to the background.

See your code, is JS sent to the PHP interface?
If so, use post,php to use $res=$_post[' data '
If your calling interface is based on, Ajax ({data:{...}});
Next, PHP gets the object, similar to the Res.name

Https://github.com/yiisoft/yi ...

Please refer to this code

http://json.cn/Test JSON format

  • 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.