2013-01-21 2 views
1

아이스크림 샌드위치, 젤리 빈은 잘 작동합니다. 그러나 이전 버전에서는 작동하지 않아야합니다.안드로이드 json 파싱 오류 (Froyo 이하)

이유를 모르겠습니다. 제발 조언 좀 해줘.

JSON 데이터 :

{ 
"ANDROID" :[ 
    { 
     "NAME" : "homepage", 
     "URL" : "http://www.stackoverflow.com", 
     "IMAGE" : "http://www.stackoverflow/menu_01.png", 
     "USE_YN" : "Y", 
     "APP_YN" : "N" 
    } 
    ]   
} 

오류 로그 :

org.json.JSONException: Value of type java.lang.String cannot be converted to JSONObject 

대상 소스 :

JSONObject jobject = new JSONObject(jsondata);     

감사합니다!

+0

코드를 표시 할 수 있습니까? – Henry

답변

1
/*"ANDROID" :[ 
       { 
        "NAME" : "homepage", 
        "URL" : "http://www.stackoverflow.com", 
        "IMAGE" : "http://www.stackoverflow/menu_01.png", 
        "USE_YN" : "Y", 
        "APP_YN" : "N" 
       } 
       ]   
      }*/ 

      //here is the code to parse 

      try { 
       String jsondata = "your server response like above statements"; 

       if (jsondata != null && !jsondata.equals("") 
         && jsondata.equalsIgnoreCase("null")) { 
        JSONObject jobject = new JSONObject(jsondata); 

        if (jobject != null) { 
         if (jobject.has("ANDROID")) { 
          JSONArray jsonArr = jobject.getJSONArray("ANDROID"); 

          if (jsonArr != null && jsonArr.length() > 0) { 
           for (int i = 0; i < jsonArr.length(); i++) { 
            JSONObject json = jsonArr.getJSONObject(i); 

            if (json != null) { 

             if (json.has("NAME")) { 
              String name = json 
                .getString("NAME"); 
             } 

             if (json.has("URL")) { 
              String url = json.getString("URL"); 
             } 

             if (json.has("IMAGE")) { 
              String image = json 
                .getString("IMAGE"); 
             } 

             if (json.has("USE_YN")) { 
              String use = json 
                .getString("USE_YN"); 
             } 

             if (json.has("APP_YN")) { 
              String app = json 
                .getString("APP_YN"); 
             } 
            } 
           } 
          } 
         } 
        } 
       } 
      } catch (Exception e) { 
       e.printStackTrace(); 
      }