Home  >  Article  >  Backend Development  >  php如何取得post 方式传递的json中的数据!

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

WBOY
WBOYOriginal
2016-06-23 13:10:111797browse



上面是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')";

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