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