<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>
php后台如何处理
instance = [{"instance_name":1,"machine_belong":2,"access_port":3},{"instance_name":1,"machine_belong":2,"access_port":3}];
用这个做了测试,是json写的不对,我代码里json是拼接的,拼接有错误
<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>
php后台如何处理
instance = [{"instance_name":1,"machine_belong":2,"access_port":3},{"instance_name":1,"machine_belong":2,"access_port":3}];
用这个做了测试,是json写的不对,我代码里json是拼接的,拼接有错误
<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解析:
<code>$instance = json_decode($_REQUEST['instance'], true);</code>
不谢
你应该把对象先转成 字串符 ,然后再发送给后台
看到你的代码,是js发往php接口?
如果是这样,用post,php可以用$res=$_post['data']
假如你的调用接口是以,ajax({data:{...}});
接下来,php的获取对象,类似res.name
https://github.com/yiisoft/yi...
请参考这个代码
http://json.cn/ 测试json格式