dsyak22488 2014-12-22 11:05
浏览 31
已采纳

我的Android应用程序不解析php生成的数据

I generate the data using php script and it shows a json data, I have my android app that parse that data. When i open that link it doesn't parse that data. but when I copy the script generated output to a file with .json extension than my app is able to parse the data. Sorry for my English. And thanks in advance. I am newbie to json. Here is my php code which generate json data.

$jsonresponse = array("members"=>array());

while($row=mysql_fetch_array($result)) 
{ 
    $row['firstname'] = ucfirst(strtolower($row['firstname']));
    $row['surname'] = ucfirst(strtolower($row['surname']));
    $id = $row['id'];
    $name = $row['firstname']." ".$row['surname'];
    $city = $row['city'];
    $jsonrow = array(
        "id"=>$id,
        "name"=>$name,
        "city"=>$city
    );

    array_push($jsonresponse["members"],$jsonrow);
}

echo json_encode($jsonresponse);

Output

{"members":[{"id":"1","name":"Sarvagna Mehta","city":"Ahmedabad"}]}

No, need to change anything in android code. Just solved my problem.

  • 写回答

1条回答 默认 最新

  • dongmangsha7354 2014-12-22 12:14
    关注

    I got the answer, I forgot to add charset=utf-8 to my PHP script. Thanks all.

    header("Content-type: text/html;charset=utf-8");
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效