0

I made a set of data and put into a JSON array and convert it to string so that I could store it into my sqlite database. When I take it out, it is a String and it has the form of a JSON array:

String temp = ["0", "1", "2", "3",.....]

Is there any easy way for me to make this into a String array, JSON array or I have to use the old fashion method(substring, split.etc)?

1
  • why not just json decode and then loop over JSONArray? Commented Aug 28, 2012 at 21:03

2 Answers 2

3

You can easily turn it back into a JSONArray by just constructing a new instance:

String jsonString;  //The string data you pulled out of the DB
JSONArray array = new JSONArray(jsonString);

If you need to go further, you could iterate over the array and turn it into a collection:

ArrayList<String> items = new ArrayList<String();
for(int i=0; i < array.length(); i++) {
    items.add(array.optString(i));
}
Sign up to request clarification or add additional context in comments.

Comments

0

Try doing like this:

JSONArray jArray = new JSONArray(jsonString);

It will simply convert your json string (which is identified by [...]) into JSONArray.

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.