json与php的传值和接收

一、Js数组转json格式传输

关键字:JSON.stringify()

var runlist= {
    aver_space: "00′00″",
    canvarsta: 1,
    space_list:[
        {dist: 5, totletime: "00:00:00"},
        {dist: 10, totletime: "00:00:00"},
        {dist: 15, space: totletime: "00:00:00"}
    ]
}

var runlist= JSON.stringify(runlist);

二、php接收Json传值

关键字:
(1)html_entity_decode()
(2)json_decode($list,true):第二参数一定要设置为true,才能以数组形式使用,否则是object形式

$runlist= $_POST['runlist'];
$runlist= html_entity_decode($runlist);
$runlist= json_decode($runlist, true);
print_r($runlist);
上一篇:编码


下一篇:代码审计学习—zzcms存储型xss