Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/310.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/189.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Android:string可以';你不能转换成JSONArray吗?_Java_Android_Json_Http - Fatal编程技术网

Java Android:string可以';你不能转换成JSONArray吗?

Java Android:string可以';你不能转换成JSONArray吗?,java,android,json,http,Java,Android,Json,Http,我可以从php的json_encode获得json响应,并且我能够在eclipse的logcat中显示响应是什么: [{"idusers":"1","full_name":"Test Subject","get_email":"test_subject@gmail.com"}, {"idusers":"2","full_name":"Test Subject_2","get_email":"test_subject_2@gmail.com"}] 现在,我正在努力 //parse jso

我可以从php的json_encode获得json响应,并且我能够在eclipse的logcat中显示响应是什么:

[{"idusers":"1","full_name":"Test Subject","get_email":"test_subject@gmail.com"},
{"idusers":"2","full_name":"Test Subject_2","get_email":"test_subject_2@gmail.com"}]
现在,我正在努力

    //parse json data
    try {
        JSONArray jArray = new JSONArray(result);
        for(int i =0; i<jArray.length(); i++){
            JSONObject json_data = jArray.getJSONObject(i);
            Log.i("log_tag","id: "+json_data.getInt("idusers")+
                    ", Full Name: "+json_data.getString("full_name")+
                    ", Email: "+json_data.getString("get_email")
                    );
        }
    }catch(JSONException e){
        Log.e("log_tag","Error parsin data "+e.toString());
    }
//解析json数据
试一试{
JSONArray jArray=新JSONArray(结果);

对于(inti=0;i尝试向JSON返回的PHP变量添加强制转换

$user_id = (int) $id;
$email = (string) $email;

您的JSON无效。第二个数组元素的“get_email”值中缺少引号(“)

应该是:

[
    {
        "idusers": "1",
        "full_name": "Test Subject",
        "get_email": "test_subject@gmail.com"
    },
    {
        "idusers": "2",
        "full_name": "Test Subject_2",
        "get_email": "test_subject_2@gmail.com"}]

发现了发生的事情。我在PHP文档中有一个字符串,没有被调用。我有一个单词“testing”,这是错误中的单词。一旦这个“testing”被删除,它就工作了。谢谢字符串结尾处缺失。这是问题的原因,还是仅仅是一个输入错误?这肯定只是一个输入错误。因为我从BufferReader获得了一个响应这是我在PHP文件
while($get=$SQL->fetch(PDO::fetch_ASSOC)){$output[]=$get;}print(json_encode($output))中传递的内容所以,从技术上讲,我并没有真正设置任何变量,它只是直接指向数组。mysql中的数据类型是varchar,这有区别吗?id是int。