Php jsonobject无法转换为jsonarray android studio

Php jsonobject无法转换为jsonarray android studio,php,android,json,Php,Android,Json,我想显示已经使用JSON上传到数据库SQL的图像 我已经为我的android和服务器端编写了这段代码 getImages.php <?php //Importing dbdetails file require_once 'dbDetails.php'; //connection to database $con = mysqli_connect(HOST,USER,PASS,DB) or die('Unable to Connect...'); //sql query to

我想显示已经使用JSON上传到数据库SQL的图像

我已经为我的android和服务器端编写了这段代码

getImages.php

<?php 

//Importing dbdetails file 
require_once 'dbDetails.php';

//connection to database 
$con = mysqli_connect(HOST,USER,PASS,DB) or die('Unable to Connect...');

//sql query to fetch all images 
$sql = "SELECT * FROM images";

//getting images 
$result = mysqli_query($con,$sql);

//response array 
$response = array(); 
$response['error'] = false; 
$response['images'] = array(); 

//traversing through all the rows 
while($row = mysqli_fetch_array($result)){
    $temp = array(); 
    $temp['id']=$row['id'];
    $temp['name']=$row['name'];
    $temp['url']=$row['url'];
    array_push($response['images'],$temp);
}
//displaying the response 
echo json_encode($response);
24405

                                                      [ 10-03 12:20:41.966 24381:24405 W/         ]
                                                      Unrecognized GLES max version string in extensions: ANDROID_EMU_CHECKSUM_HELPER_v1
ANDROID_EMU_dma_v1 10-03 12:20:41.983 24381-24405/?I/opengl渲染器: 初始化EGL,版本1.4 10-03 12:20:41.983 24381-24405/? D/OpenGLRenderer:交换行为110-03 12:20:41.984 24381-24405/? W/OpenGLRenderer:无法使用选择配置 EGL\u交换\u行为\u保留,重试时没有。。。10-03 12:20:41.984 24381-24405/? D/OpenGLRenderer:交换行为0 10-03 12:20:41.993 24381-24405/? D/EGL_仿真:eglCreateContext:0x9dffc920:主要2分钟 0 rcv 2 10-03 12:20:42.040 24381-24405/?D/EGL_仿真: eglMakeCurrent:0x9dffc920:ver 2 0(tinfo 0x9df9f670)10-03 12:20:42.403 24381-24405/? D/EGL_仿真:eglMakeCurrent: 0x9dffc920:ver 2 0(tinfo 0x9df9f670)10-03 12:20:42.670 24381-24405/net.simplifiedcoding.androidcustomgridview D/EGL_仿真:eglMakeCurrent:0x9dffc920:ver 2 0(tinfo 0x9df9f670)10-03 12:20:42.825 24381-24381/net.simplifiedcoding.androidcustomgridview W/art:之前 安卓4.1,方法int android.support.v7.widget.ListViewCompat.lookForSelectablePosition(int, boolean)将错误地重写包私有方法 在android.widget.ListView 10-03 12:20:42.864中 24381-24381/net.simplifiedcoding.androidcustomgridview W/System.err: org.json.JSONException:image 10-03 12:20:42.865没有值 24381-24381/net.simplifiedcoding.androidcustomgridview W/System.err:
在org.json.JSONObject.get(JSONObject.java:389)10-03 12:20:42.865 24381-24381/net.simplifiedcoding.androidcustomgridview W/System.err:
位于org.json.JSONObject.getString(JSONObject.java:550)10-03 12:20:42.865 24381-24381/net.simplifiedcoding.androidcustomgridview W/System.err:at net.simplifiedcoding.androidcustomgridview.MainActivity.showGrid(MainActivity.java:96) 10-03 12:20:42.865 24381-24381/net.simplifiedcoding.androidcustomgridview W/System.err:
在 net.simplifiedcoding.androidcustomgridview.MainActivity.access$000(MainActivity.java:22) 10-03 12:20:42.865 24381-24381/net.simplifiedcoding.androidcustomgridview W/System.err:
在 net.simplifiedcoding.androidcustomgridview.MainActivity$1.onResponse(MainActivity.java:66) 10-03 12:20:42.882 24381-24381/net.simplifiedcoding.androidcustomgridview W/System.err:
在 net.simplifiedcoding.androidcustomgridview.MainActivity$1.onResponse(MainActivity.java:58) 10-03 12:20:42.882 24381-24381/net.simplifiedcoding.androidcustomgridview W/System.err:
在 com.android.volley.toolbox.JsonRequest.deliverResponse(JsonRequest.java:65) 10-03 12:20:42.882 24381-24381/net.simplifiedcoding.androidcustomgridview W/System.err:
在 com.android.volley.ExecutorDelivery$ResponseDeliveryRunnable.run(ExecutorDelivery.java:99) 10-03 12:20:42.882 24381-24381/net.simplifiedcoding.androidcustomgridview W/System.err:
在android.os.Handler.handleCallback(Handler.java:751)10-03 12:20:42.882 24381-24381/net.simplifiedcoding.androidcustomgridview W/System.err:at android.os.Handler.dispatchMessage(Handler.java:95)10-03 12:20:42.882 24381-24381/net.simplifiedcoding.androidcustomgridview W/System.err:
在android.os.Looper.loop(Looper.java:154)10-03 12:20:42.882 24381-24381/net.simplifiedcoding.androidcustomgridview W/System.err:
在android.app.ActivityThread.main(ActivityThread.java:6077)10-03 12:20:42.882 24381-24381/net.simplifiedcoding.androidcustomgridview W/System.err:at java.lang.reflect.Method.invoke(本机方法) 10-03 12:20:42.882 24381-24381/net.simplifiedcoding.androidcustomgridview W/System.err:
在 com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:866) 10-03 12:20:42.882 24381-24381/net.simplifiedcoding.androidcustomgridview W/System.err:
位于com.android.internal.os.ZygoteInit.main(ZygoteInit.java:756)


您没有从PHP返回JSON数组。直接回显
json\u encode($temp)
,而不将其推入数组,或者使用
JSONObjectRequest
而不是
JSONArrayRequest
并相应地解析它。

您不是从PHP返回json数组。可以直接回显
json\u encode($temp)
而不将其推入数组,或者使用
JSONObjectRequest
而不是
JSONArrayRequest
并相应地解析它。

更改getData以接受JSONObject。您正在从服务器传递Jsonobject

 private void getData(){
    //Showing a progress dialog while our app fetches the data from url
    final ProgressDialog loading = ProgressDialog.show(this, "Please wait...","Fetching data...",false,false);

    //Creating a json array request to get the json from our api
    JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(Method.GET,DATA_URL,null,
            new Response.Listener<JSONObject>() {
                @Override
                public void onResponse(JSONObject response) {
                    //Dismissing the progressdialog on response
                    loading.dismiss();
                    try{
                    //Displaying our grid
                    showGrid(response.getJSONArray("images");
                    }catch(Exception e){}
                }
            },
            new Response.ErrorListener() {
                @Override
                public void onErrorResponse(VolleyError error) {
                    loading.dismiss();
                    Toast.makeText(getApplicationContext(), error.getMessage() + ".", Toast.LENGTH_LONG).show();
                }
            }
    );

    //Creating a request queue
    RequestQueue requestQueue = Volley.newRequestQueue(this);
    //Adding our request to the queue
    requestQueue.add(jsonObjectRequest);
}
private void getData(){
//当我们的应用程序从url获取数据时显示进度对话框
final ProgressDialog loading=ProgressDialog.show(这是“请稍候…”,“正在获取数据…”,false,false);
//创建json数组请求以从api获取json
JsonObjectRequest JsonObjectRequest=新的JsonObjectRequest(Method.GET,DATA_URL,null,
新的Response.Listener(){
@凌驾
公共void onResponse(JSONObject响应){
//在响应时取消progressdialog
loading.dispose();
试一试{
//显示我们的网格
showGrid(response.getJSONArray(“图像”);
}捕获(例外e){}
}
},
新的Response.ErrorListener(){
@凌驾
公共无效onErrorResponse(截击错误){
loading.dispose();
Toast.makeText(getApplicationContext(),error.getMessage()+”,Toast.LENGTH_LONG.show();
}
}
);
//创建请求队列
RequestQueue RequestQueue=Volley.newRequestQueue(this);
//将我们的请求添加到队列中
add(jsonObjectRequest);
}

更改getData以接受JSONObject。您正在传递Jsonob
                                                      [ 10-03 12:20:41.965 24381:24405 D/         ]
                                                      HostConnection::get() New Host Connection established 0x9dfa0b80, tid
                                                      [ 10-03 12:20:41.966 24381:24405 W/         ]
                                                      Unrecognized GLES max version string in extensions: ANDROID_EMU_CHECKSUM_HELPER_v1
 private void getData(){
    //Showing a progress dialog while our app fetches the data from url
    final ProgressDialog loading = ProgressDialog.show(this, "Please wait...","Fetching data...",false,false);

    //Creating a json array request to get the json from our api
    JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(Method.GET,DATA_URL,null,
            new Response.Listener<JSONObject>() {
                @Override
                public void onResponse(JSONObject response) {
                    //Dismissing the progressdialog on response
                    loading.dismiss();
                    try{
                    //Displaying our grid
                    showGrid(response.getJSONArray("images");
                    }catch(Exception e){}
                }
            },
            new Response.ErrorListener() {
                @Override
                public void onErrorResponse(VolleyError error) {
                    loading.dismiss();
                    Toast.makeText(getApplicationContext(), error.getMessage() + ".", Toast.LENGTH_LONG).show();
                }
            }
    );

    //Creating a request queue
    RequestQueue requestQueue = Volley.newRequestQueue(this);
    //Adding our request to the queue
    requestQueue.add(jsonObjectRequest);
}