2017-10-08 1 views
1

배열 목록을 서버에 게시하고 배열 목록을 구문 분석하여 데이터베이스에 저장하지만 iam이 응답을 읽을 수 없습니다. 누군가가 iam이 soultion을 지탱할 수 없도록 도와 줄 수 있습니다.안드로이드에서 asynchttp를 사용하여 안드로이드에서 PHP에서 json 응답을 읽는 방법?

내가이 응 답을 읽을 수있는 방법을

$json = $_POST["usersJSON"]; 

    //Remove Slashes 

    if (get_magic_quotes_gpc()){ 

    $json = stripslashes($json); 

    } 

    //Decode JSON into an Array 
12 
    $data = json_decode($json); 

    //Util arrays to create response JSON 

    $a=array(); 

    $b=array(); 

    //Loop through an Array and insert data read from JSON into MySQL DB 

    for($i=0; $i<count($data) ; $i++) 

    { 
     //inserting data in to the database 
     i++; 
     } 
    if(i<0) 
    { 
      $response['error']=true; 
      $response['message']="data inserted"; 
    } 
    else 
    { 
     $response['error']=false; 
     $response['message']="error occured"; 
     } 
    echo json_encode ($response) 

- : PHP 코드 여기

public void confirmOrder(final String name, final String price, final String quantity, final String cost, final String sellerid) 
    { 
      AsyncHttpClient httpClient = new AsyncHttpClient(); 
      RequestParams params = new RequestParams(); 
      ArrayList<HashMap<String,String>> productList= dbHelper.getAllProducts(); 

      if(productList.size()!=0) 
      { 
       pDialog.show(); 
       params.put("OrderSummary",dbHelper.getAllproducts()); 
       httpClient.post(APIURL.API_URL, params, new AsyncHttpResponseHandler() { 
        @Override 
        public void onSuccess(int statusCode, Header[] headers, byte[] responseBody) { 

        } 

        @Override 
        public void onFailure(int statusCode, Header[] headers, byte[] responseBody, Throwable error) { 

        } 
       }); 
      } 
      else 
      { 
       Toast.makeText(getApplicationContext(),"List Empty",Toast.LENGTH_LONG).show(); 
      } 

    } 

하고 - 다음은

는 안드로이드 자바 코드 내 자바 프로그램에 전자? 즉 GSON를 사용하는 POJO JSON에 쐐기를 파싱 한 후 HTTP 상태 코드 (200)는 onSuccess 체크

답변

0

다음이

String str = IOUtils.toString(responseBody, "UTF-8"); 

같은 응답 바이트 배열을 분석. 성공과 실패 모두 동일하게 수행하십시오.

관련 문제