当前位置:Gxlcms > PHP教程 > php如何取得post方式传递的json中的数据!

php如何取得post方式传递的json中的数据!

时间:2021-07-01 10:21:17 帮助过:21人阅读

上面是post方式传递的json数据;
php中如何接收并将这些数据保存到数据库呢?
请高手指教!!


回复讨论(解决方案)

$_POST 呀
如果是 php 收到的数据,用 json_decode 解码,如不是 utf-8 编码的,需转换成 utf-8

如果 $_POST 中无值,则用 file_get_contents('php://input') 接收(手册中都有说明)

本人新手,能不能给发个范例啊!

$arr = json_decode($_POST['json'], true);print_r($arr);  就是数组了,接下来保存数据库不就简单了

自己研究了下搞定了,post取不到数据,用的input

$data=file_get_contents("php://input"); //取得json数据 $data = json_decode($data, TRUE);   //格式化 $a1= $data['form']; $a2= $data['entry']['field_1']; $sql1="insert into xxx (a1,a2) values ('$a1','$a2')";

人气教程排行