Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Converting from JSONArray to String then back again

I need to store a JSONArray object as a string then retrieve the string and convert it back to a JSONArray.

If I do:

JSONArray jArray; String s = jArray.toString() JSONArray newJArray = new JSONArray(s); 

Will I get back the same object?

I'm trying to store a JSONArray in a SQLite database.

Here's what I'm looking at. http://developer.android.com/reference/org/json/JSONArray.html#toString()

like image 437
Nick Rempel Avatar asked May 12 '11 20:05

Nick Rempel


People also ask

Can we convert JSON array to string?

int size = exampleList. size(); String[] stringArray = exampleList. toArray(new String[size]); This will convert our JSON array into a String array.

Can we convert JSONArray to JSONObject?

We can also add a JSONArray to JSONObject. We need to add a few items to an ArrayList first and pass this list to the put() method of JSONArray class and finally add this array to JSONObject using the put() method.

How do I check if a string is Jsonarject or JSONArray?

JSONObject json = RestManager. getJSONfromURL(myuri); // retrieve the entire json stream JSONArray interventionJsonArray = json. getJSONArray("intervention"); In the first case, the above doesn't work because there is only one element in the stream..

How do I remove an object from JSONArray?

You can remove an element from the JSONArray object using the remove() method. This method accepts an integer and removes the element in that particular index.


1 Answers

As long as it's a valid JSONArray to begin with, then yes.

like image 179
Jason Robinson Avatar answered Oct 11 '22 06:10

Jason Robinson