Home >Backend Development >PHP Tutorial >[Solved] How does php parse such a json string?

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

WBOY
WBOYOriginal
2016-10-11 14:23:501125browse

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

[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>

[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>

PHP analysis:

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

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

Statement:
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