0

i have this input:

[
"1",
"2",
"3",
"5",
"6",
"9",
"10"
]

Could anyone tell me how to parse this kind of json file, that I get from the web? It doesn't have any key for the attribute or something like that.

1
  • did you check this out: json.org . It's an array! Commented Nov 29, 2013 at 11:53

3 Answers 3

2

Try this..

JSONArray array = new JSONArray(response);  // get the response as JSONArray

for(int i=0; i < array.length(); i++)
{                   
    Log.v("ALL--", array.getString(i));   // get the values as string using for loop
}
Sign up to request clarification or add additional context in comments.

Comments

2

With org.json package, like this (assuming it is in a string):

JSONArray myJSONArray = new JSONArray(inputString);

You can then get the individual elements using:

myJSONArray.getString(i);

Comments

2

You are having JSONArray as your response string so you need to create JSONArray for that

JSONArray jsonArray = new JSONArray(responseString);

Now, you can retrieve the values by their index positions.like,

for(int i = 0; i < jsonArray.length(); i++){
   String value = jsonArray.getString(i);
}

Complete code to parse this JSON is,

JSONArray jsonArray = new JSONArray(responseString);
for(int i = 0; i < jsonArray.length(); i++){
   String value = jsonArray.getString(i);
}

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.