android中的JSONException?

时间:2012-04-14 15:06:43

标签: java php android json phpmyadmin

baseposte是我的数据库,User是一个包含Num_Compte和Code_Compte的表

 Log.i(getClass().getSimpleName(), "send  task - start");

   ResponseHandler<String> responseHandler = new BasicResponseHandler();
        String responseBody = httpclient.execute(httppost,responseHandler);
        JSONObject json2 = new JSONObject(responseBody);
        JSONArray jArray = json2.getJSONArray("posts");
    ArrayList<HashMap<String, String>> mylist = new ArrayList<HashMap<String, String>>();


     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 “baseposte”:数据库, “user”:是表包含(Cin,Num_Compte,Code_Compte,Etat)

<?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');
    echo (json_encode(array('posts'=>$posts)));

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

我有这个结果:

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

我不明白问题出在哪里。

0 个答案:

没有答案