1

Ice Cream Sandwich, jelly beans will work just fine. However, it should not work with earlier versions.

I do not know why. Give me some advice please.

jSon data :

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

error log :

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

target source :

JSONObject jobject = new JSONObject(jsondata);                  

Thank you!

1
  • Can you show us the code? Commented Jan 21, 2013 at 8:36

1 Answer 1

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();
            }
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.