0

I have a serialized json string in the format:

"[{\"Version\":\"8.63\",\"Date\":\"07\/11\/2011 00:00:00\",\"Count\":213},
{\"Version\":\"1.0\",\"Date\":\"07\/11\/2011 00:00:00\",\"Count\":1},
.........
,{\"Version\":\"7.7\",\"Date\":\"31\/10\/2011 00:00:00\",\"Count\":0}]"

I want to break down this string into an array of jsonObjects. I know if you have a string containing only one jsonObject then we can easily create a jsonObject.

Any help would be appreciated,

Thanks

2 Answers 2

2

If you really want an array of JSONObjects and not a JSONArray you can do this this way:

JSONArray array = new JSONArray(string);
JSONObject[] objects = new JSONObject[array.length()];
for(int i = 0; i < array.length(); i++) {
    objects[i] = array.getJSONObject(i);
}
Sign up to request clarification or add additional context in comments.

3 Comments

I added the brackets on the "objects" array declaration
it gives me a type mismatch error when I convert it into JSONArray.
Then you dont have an invalid JSONArray string representation.
1

You can create a

new JSONArray(withYourString);

1 Comment

when I create a JSONArray with my string it gives me the following error:: WARN/System.err(332): org.json.JSONException: Value [{"Version":"(All)","Date":"07/11/2011 00:00:00","Count":332} WARN/System.err(332): at org.json.JSON.typeMismatch(JSON.java:107),WARN/System.err(332): at org.json.JSONArray.<init>(JSONArray.java:91) , so I am unable to convert it into JSONArray

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.