android中的JSONException

时间:2012-04-14 00:46:15

标签: php android json phpmyadmin

LoginActivity.java

baseposte是我的数据库,User是一个包含Num_CompteCode_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错误  JSONException: Value <br of type java.lang.String cannot be converted to JSONObject

我不明白问题出在哪里。

0 个答案:

没有答案