Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/220.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
Android 从http格式化响应数组_Android_Parsing_Android Asynctask_Httpresponse_Android Maps V2 - Fatal编程技术网

Android 从http格式化响应数组

Android 从http格式化响应数组,android,parsing,android-asynctask,httpresponse,android-maps-v2,Android,Parsing,Android Asynctask,Httpresponse,Android Maps V2,请帮助我格式化来自http的响应。 使用AsynckTask过帐 protected String doInBackground(String... params) { // TODO Auto-generated method stub HttpClient httpclient = new DefaultHttpClient(); HttpPost httppost = new HttpPost("http/test.php");

请帮助我格式化来自http的响应。 使用AsynckTask过帐

protected String doInBackground(String... params) {
        // TODO Auto-generated method stub
         HttpClient httpclient = new DefaultHttpClient();

            HttpPost httppost = new HttpPost("http/test.php");

            try {
                // Add user name and password
             String latitude = "44.754535";
             String longitude = "11.178589";
             String range = "222";



               List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair(2);
                nameValuePairs.add(new BasicNameValuePair("latitude", latitude));
                nameValuePairs.add(new BasicNameValuePair("longitude",longitude));
                nameValuePairs.add(new BasicNameValuePair("range", range));

                httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));

                // Execute HTTP Post Request
                Log.w("SENCIDE", "Execute HTTP Post Request");
                HttpResponse response = httpclient.execute(httppost);

                String str = inputStreamToString(response.getEntity().getContent()).toString();
                Log.w("SENCIDE", str);

                if(str.toString().contains("da"))
                {

                content=str.toString();

                }else
                {

                 System.out.print(str);             
                }

            } catch (ClientProtocolException e) {
             e.printStackTrace();
            } catch (IOException e) {
             e.printStackTrace();
            }
            return content;
        } 
`

因此,我们的目标是在不改变php部分的情况下,仅拥有16.07公里的da Motta。 看到aray中有3个项目,有一些想法从数组中获取第3个对象。
Tnx。您将从服务器获得JSONObject作为响应。您可以从中获取以下值:

// convert Response String to JSONObject
JSONObject json=new JSONObject(str); //str=response string from server

// set error_message from json
String str_error_message=json.getString("error_message");

// set success from json
String str_success=json.getString("success");

出于好奇,inputStreamToString是什么(EntityUtils.toString()没有做什么?)如果你问我的话,这是一条奇怪的错误消息
// convert Response String to JSONObject
JSONObject json=new JSONObject(str); //str=response string from server

// set error_message from json
String str_error_message=json.getString("error_message");

// set success from json
String str_success=json.getString("success");