>我以这种形式从我的安卓应用程序的 php 文件中获得了我的 json 响应
[{"countryname":"India","flag":"http:'/'/india.in'/india.png"}]
我需要这种形式,请给我一些帮助。
{"countries":[{"countryname":"India","flag":"http:'/'/india.in'/india.png"}]}
你有 php 中的数组,你将其编码为 json。现在你需要像这样添加另一个数组级别:
$country = array('countryname' -> 'India', ...);
$countries = array('countries' => $country );
echo json_encode($countries);
这只是我的猜测,因为你没有显示任何代码。
更新
$sql=mysql_query("select * from t1 ORDER BY timestamp DESC");
while($row=mysql_fetch_assoc($sql)) {
$output[]=$row;
}
// json_encode($output); doesn't do anything useful
$countries = array('countries' => $output);
echo json_encode($countries);