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 这是哪个作者做的宝宝起名网站
    • ¥60 版本过低apk如何修改可以兼容新的安卓系统
    • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
    • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
    • ¥50 有数据,怎么用matlab求全要素生产率
    • ¥15 TI的insta-spin例程
    • ¥15 完成下列问题完成下列问题
    • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
    • ¥15 YoloV5 第三方库的版本对照问题
    • ¥15 请完成下列相关问题!