2014-10-24 3 views
0

에 JSON의 값을 취득하는 것은 귀하가 JSONArray로 된 JSONObject로 변환하려고안드로이드 응용 프로그램

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"); 
       } 

답변

0

안드로이드 응용 프로그램에서 JSON의 값을 가져옵니다.

사용이

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"); 
      } 
관련 문제