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 安装svn网络有问题怎么办
    • ¥15 Python爬取指定微博话题下的内容,保存为txt
    • ¥15 vue2登录调用后端接口如何实现
    • ¥65 永磁型步进电机PID算法
    • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
    • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
    • ¥15 如何处理复杂数据表格的除法运算
    • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
    • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
    • ¥15 latex怎么处理论文引理引用参考文献