[Solved] How does php parse such a json string?

WBOY
Release: 2016-10-11 14:23:50
Original
1106 people have browsed it

<code>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}]



</code>
Copy after login
Copy after login

[Solved] How does php parse such a json string?

How to handle php background

instance = [{"instance_name":1,"machine_belong":2,"access_port":3},{"instance_name":1,"machine_belong":2,"access_port":3}];

I did a test with this, and it turned out that the json was written incorrectly. The json in my code was spliced, and there was an error in the splicing

Reply content:

<code>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}]



</code>
Copy after login
Copy after login

[Solved] How does php parse such a json string?

How to handle php background

instance = [{"instance_name":1,"machine_belong":2,"access_port":3},{"instance_name":1,"machine_belong":2,"access_port":3}];

I did a test with this, and it turned out that the json was written incorrectly. The json in my code was spliced, and there was an error in the splicing

<code>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);</code>
Copy after login

PHP analysis:

<code>$instance = json_decode($_REQUEST['instance'], true);</code>
Copy after login

No thanks

You should convert the object into a string first and then send it to the background

See your code, is js sent to the php interface?
If so, when using post, PHP can use $res=$_post['data']
If your calling interface is ajax({data:{...}});
Next, get PHP Object, similar to res.name

https://github.com/yiisoft/yi...

Please refer to this code

http://json.cn/ Test json format

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template