Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/213.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应用程序中获取json值_Java_Android_Json - Fatal编程技术网

Java 在android应用程序中获取json值

Java 在android应用程序中获取json值,java,android,json,Java,Android,Json,在android应用程序中获取json值 my json result = {"message":"Json","success":1} Value {"message":"Json","success":1} of type org.json.JSONObject cannot be converted to JSONArray my code : HttpEntity ent= resp.getEntity(); te

在android应用程序中获取json值

my json result = {"message":"Json","success":1}

Value {"message":"Json","success":1} of type org.json.JSONObject cannot be converted to JSONArray

my code :

                HttpEntity ent= resp.getEntity();


                text = EntityUtils.toString(ent);

                JSONArray json = new JSONArray(text);
                JSONObject jObj = json.getJSONObject(0);
                Integer sucess= jObj.getInt("success");

                if (sucess == 1){
                    Log.v("JSON" ,"es 1");
                }

您正在尝试将JSONObject转换为JSONArray

用这个

HttpEntity ent= resp.getEntity();


            text = EntityUtils.toString(ent);

            JSONObject json = new JSONObject(text);

            int success= -1;
            if(json.has("success"))
                success = json.getInt("success");

            if (success == 1){
                Log.v("JSON" ,"es 1");
            }