-3

I have a weird problem and I hope that you can help me with it..

The problem is as follows: I have created a javacode to resolve a query from JSON but I can't parse it to a String... I also tried to get the String 0, but that also does not work.

Underneath, the code from Java:

JSONArray json_data = new JSONArray(result);
           for (int i = 0; i < json_data.length(); i++) {
                code = json_data.getJSONObject(i).getInt("code");
                pictureID = json_data.getJSONObject(i).getString(
                        "Picture_ID");
                System.out.println(code);
                System.out.println(pictureID);
            }

This is the response I get from JSON:

[{"code":1}][{"Picture_ID":"74","0":"74"}]

But this is the error I get from the catch clause:

org.json.JSONException: No value for Picture_ID

Again, Thank you very much for helping out!

Kjell
  • 432
  • 4
  • 11

1 Answers1

-1

Once you check key value "Picture_ID" is correct, if it correct try with this code...

for (int i = 0; i < innerProjectarray.length(); i++) {

JSONObject obj = innerProjectarray.getJSONObject(i);

String projNum = obj.optString("code"); 
String projName = obj.optString("Picture_ID"); 
// and use both values. 
}
RanjithReddy
  • 47
  • 2
  • 7
  • Hmm, now I'm getting no value for Picture_ID anymore... But how can I get the value from the JSON response if the key is incorrect? – Kjell May 27 '14 at 14:12
  • This is valid json.... { "phoneNumber": [ { "type": "work", "num": "11111" }, { "type": "home", "num": "2222" } ], "address": { "state": "World", "address": "infinite space, 000", "city": "Android city" }, "surname": "Swa", "name": "Android" } – RanjithReddy May 27 '14 at 14:18