值类型java.lang.String的连接无法转换为JSONArray

时间:2017-01-26 14:51:47

标签: android sql android-studio

这是我的代码我得到错误值类型java.lang.String的连接无法转换为JSONArray。有人可以帮忙吗

    OkHttpClient client = new OkHttpClient();
    Request request = new Request.Builder().url("http://10.0.3.2/filipdownload.php?list_files").build();

    Response response = null;
    try {
        response = client.newCall(request).execute();
        JSONArray array = new JSONArray(response.body().string());

        for (int i = 0; i <array.length(); i++){

            String file_name = array.getString(i);

            if(files_on_server.indexOf(file_name) == -1)
                files_on_server.add(file_name);
        }


        handler.post(new Runnable() {
            @Override
            public void run() {
                arrayAdapter.notifyDataSetChanged();
            }
        });


    } catch (IOException e) {
        e.printStackTrace();
    } catch (JSONException e) {
        e.printStackTrace();
    }
}
});

这是我的PHP代码

if(isset($_GET["list_files"]))
{

    $files=array();    
    foreach(glob('uploads/*.*') as $file) {
        array_push($files, basename($file));            
    }    
    header('Content-type: application/json');
    echo json_encode($files);

0 个答案:

没有答案