我试图在PHP上解析Android上发布的JSON内容。我发布的JSON内容是:
{"username":"myName","password":"myPassword"}
我正在尝试解析它,但我的代码无法正常工作,我在android中得到<br />
。
出了什么问题?我该如何解决?
我的代码
<?php
$entityBody1 = file_get_contents('php://input');
$entityBody = json_decode($entityBody1);
$test = [
['username'=>$entityBody->username,'password'=>'username'],
['username'=>'username','password'=>'username'],
];
/*
$test = [
['username'=>$entityBody1['username'],'password'=>'username'],
['username'=>'username','password'=>'username'],
];
*/
echo json_encode($test);
?>
var_dump
结果是:
string(41) "{"password":"pishguy","username":"mahdi"}"
答案 0 :(得分:-1)
您应该将assoc标志设置为true以生成数组。缔合
json_decode($entityBody1, true)