【发布时间】:2013-08-29 10:51:20
【问题描述】:
我有这个 JSON
{
"count":"3",
"num":"1",
"array":[
{
"id":"a_a",
"amount":56,
"duration":"0:12",
"time":1234566,
"type":0
},
{
"id":"a_a",
"amount":56,
"duration":"0:12",
"time":1234566,
"type":1
}
]
}
在android中创建并通过**HttpPost**
发送
,我尝试了很多方法来获取php中的数据,我的php文件是这样的:
<?php
$response = array();
//$json_data = json_encode(stripslashes($_POST['jsonarray']))
$josn = file_get_contents("php://input");
$json_data = json_decode($josn,true);
$count = $json_data->{'count'};
$num = $json_data["num"];
$response["data"]=$count;
$response["data2"]=$num;
// echoing JSON response
echo json_encode($response);
?>
但是$count 和$num 总是返回null,请大家帮忙,谢谢。
【问题讨论】:
-
您确定
$josn有任何价值吗?你能告诉我们输出吗? -
是的,它返回
{\\\"count\\\":\\\"2\\\",\\\"num\\\":\\\"1\\\",\\\"array\\\":[{\\\"id\\\":\\\"a_a\\\",\\\"amount\\\":56,\\\"duration\\\":\\\"0:12\\\",\\\"time\\\":1234566,\\\"type\\\":0},{\\\"id\\\":\\\"a_a\\\",\\\"amount\\\":56,\\\"duration\\\":\\\"0:12\\\",\\\"time\\\":1234566,\\\"type\\\":1},{\\\"id\\\":\\\"a_a\\\",\\\"amount\\\":56,\\\"duration\\\":\\\"0:12\\\",\\\"time\\\":1234566,\\\"type\\\":2}]} -
那么
$json_data输出什么? -
我知道它有点混乱抱歉,当我尝试
stripslashes($_REQUEST['jsonarray'])我有{\"count\":\"2\",\"num\":\"1\",\"array\":[{\"id\":\"a_a\",\"amount\":56,\"duration\":\"0:12\",\"time\":1234566,\"type\":0},{\"id\":\"a_a\",\"amount\":56,\"duration\":\"0:12\",\"time\":1234566,\"type\":1},{\"id\":\"a_a\",\"amount\":56,\"duration\":\"0:12\",\"time\":1234566,\"type\":2}]} -
运行 stripslashes 两次。