Parse在PHP中发布了JSON字符串格式

时间:2015-11-10 07:44:09

标签: php json

我试图在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"}"

1 个答案:

答案 0 :(得分:-1)

您应该将assoc标志设置为true以生成数组。缔合

json_decode($entityBody1, true)