Parsing an "array" string JSON with JAVA

Viewed 33

I have data coming from a websocket in JSON format.

{"Type":112,"F":[1,2,3974.909912109375,27500,1639207185]}

Im parsing it like this...

obj = new JSONObject(text);
Object o = obj.get("F");
System.out.println(o);

Which gives me...

[1,2,3974.909912109375,27500,1639207185]

In the console.

My question is, is this a string or an object or what is it? I can't seem to access the indexes.

  o.get(0);

If I try to cast it to a string, my program crashes???

 String s = (String) o;

So I have no idea what this is? And how to access the data in it. Any ideas?? As to what this actually is?? Is it just an Array?? I feel like its simply a string, but its not???

I simply what to read the values....ie

 o[0] = 1;   o[3] = 27500

  
1 Answers

Figured it out...

obj = new JSONObject(text);
JSONArray jArr = (JSONArray) obj.get("F");

Then I can do

 jArr.get(0);  etc...
Related