从Mysql计数到ModelClass android studio

尝试将COUNT行MySQL表添加到ModelCLass时,我搜索了几乎所有要使用的方法,这是唯一有意义但无法理解问题的方法,或者如果有人可以帮助我就出错了...提前致谢

错误

 D/Volley: onError: com.androidnetworking.error.ANError: org.json.JSONException: Value {"count":4} of type org.json.JSONObject cannot be converted to JSONArray

的PHP

$query = "SELECT ML.* FROM search ML INNER JOIN activity M ON M.activity_id = ML.activity_id  ORDER BY date_from ASC";
$sql = mysqli_query($conn, $query);
$num_rows = mysqli_num_rows($sql);
$output = array("count" => $num_rows);
$result = array(); 
while($row = mysqli_fetch_array($sql)){
array_push($result, array(

  'activity_img'=>$row[8],
  'company_name'=>$row[9],
  'user_id'=>$row[10]));
}
 echo json_encode($output);
 echo json_encode($result); 

爪哇

 private void getData() {
    AndroidNetworking.get("http://10.0.2.2/Final/search.php")
            .setPriority(Priority.LOW)
            .build()
            .getAsJSONArray(new JSONArrayRequestListener() {
                @Override
                public void onResponse(JSONArray response) {
                    Log.d(TAG, "onResponse: " + response);
                    {

                        try {
                            for (int i = 0; i < response.length(); i++) {
                                JSONObject data = response.getJSONObject(i);

                                promotModelClassList.add(new PromotModelClass(

                                        data.getString("activity_img"),
                                        data.getString("company_name"),
                                     data.getJSONArray("output").getJSONObject(0).getString("count")

                                ));

                            }

                            PromotAdapter adapter = new PromotAdapter(promotModelClassList, getContext());
                            promotRecycler.setAdapter(adapter);


                        } catch (JSONException e) {
                            e.printStackTrace();
                        }
                    }
                } @Override
                public void onError(ANError error) {
                    Log.d(TAG, "onError: " + error);
                }
            });
}
评论