dongpo0409 2012-04-14 00:46
浏览 103

android中的JSONException

LoginActivity.java

baseposte is my Database, User is a table which containt Num_Compte and Code_Compte

 for (int i = 0; i < jArray.length(); i++) {
     HashMap<String, String> map = new HashMap<String, String>();
     JSONObject e = jArray.getJSONObject(i);
     String s = e.getString("post");
     JSONObject jObject = new JSONObject(s);

     map.put("num", jObject.getString("nomcompte"));
     map.put("code", jObject.getString("codecompte"));

     mylist.add(map);
}

connect.php

<?php 
    $json = file_get_contents('php://input');
    $obj = json_decode($json);

    $link = mysql_connect('localhost','root','') or die('Cannot connect to the DB');
    mysql_select_db('baseposte',$link) or die('Cannot select the DB');

    $query = "SELECT * FROM user where ".$obj->{'numcompte'}."=Num_Compte and ".$obj->{'codecompte'}."=Code_Compte";
    $result = mysql_query($query) ;

     /* create one master array of the records */
    $posts = array();
    if(mysql_num_rows($result)) {
      while($post = mysql_fetch_assoc($result)) {
        $posts[] = array('post'=>$post);
      }
    }
    header('Content-type: application/json');
    print(json_encode(array('posts'=>$posts)));

      /* disconnect from the db */
    @mysql_close($link);
  ?>

LogCat Error JSONException: Value <br of type java.lang.String cannot be converted to JSONObject

I don't understand where is the problem.

  • 写回答

0条回答

    报告相同问题?

    悬赏问题

    • ¥15 phython路径名过长报错 不知道什么问题
    • ¥15 深度学习中模型转换该怎么实现
    • ¥15 HLs设计手写数字识别程序编译通不过
    • ¥15 Stata外部命令安装问题求帮助!
    • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
    • ¥15 TYPCE母转母,插入认方向
    • ¥15 如何用python向钉钉机器人发送可以放大的图片?
    • ¥15 matlab(相关搜索:紧聚焦)
    • ¥15 基于51单片机的厨房煤气泄露检测报警系统设计
    • ¥15 Arduino无法同时连接多个hx711模块,如何解决?