0

i wan to get values from a json string that looks like that in my java programm: {"2":["1.1.9.1","abc","1398422038"],"1":["75.224.11.33","test","1398384362"],"0":["125.234.22.33","test","1398382882"],"_size":3}

I tried it like that:

int length = result.optInt("_size");

for (int i = 0; i < length; i++) {
    JSONArray result2 = result.getJSONArray(String.valueOf(i));
    IPBans.addBan(result2.getString(0), 
            result2.getString(1), 
            result2.getString(3));
}

But it does not work. result is the JSONObject.

1 Answer 1

2

You have only 3 sub items for each array, so you need to index 0,1,2. Searching fo element in 3° position will always fail.

Try to change

result2.getString(3)

to

result2.getString(2)
Sign up to request clarification or add additional context in comments.

1 Comment

Super, it works. Thank you so mouch! I am too bad :/

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.