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

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

WBOY
Release: 2016-06-23 13:10:11
Original
1908 people have browsed it



上面是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);  就是数组了,接下来保存数据库不就简单了
Copy after login

自己研究了下搞定了,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')";
Copy after login

source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template