Reputation: 1059
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)?
Upvotes: 0
Views: 95
Reputation: 63303
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));
}
Upvotes: 3
Reputation: 68187
Try doing like this:
JSONArray jArray = new JSONArray(jsonString);
It will simply convert your json string (which is identified by [...]) into JSONArray
.
Upvotes: 0