EDIT: Im parsing a JSON. The JSON have this form
{
"responseObject": {
"slots_0": [
{ //SlotItem (date, string, int, boolean },
{ //SlotItem }
],
"slots_1": [
{ //SlotItem (date, string, int, boolean },
{ //SlotItem }
{ //SlotItem }
]
},
"messages" : "Hi Stackoverflow"
}
I can't parse my response with slot_0, slot_1 because I can have more that only two actually I can have slot_n, responseObject will be an array of arrays of SlotItems, if Im not wrong.
I make this parsing first (Because I only need responseObject)
Hashmap <String, String> response = (Hashmap<String, String>) response.get("responseObject")
So after that I try to make an ArrayList<SlotItem []>
Prior my edit I was trying this way:
I want to have an ArrayList of an array of Objects
ArrayList <SlotItem []> slotsinfo
Inside the ArrayList I have this structure:
enter image description here
I want to get a simple ArrayList, not a LinkedHashMap.
Because I want to retrieve the information in this way
String storeId = slotsinfo.get(index).getStoreId();
Inside SlotItem I have getters and setters.
I try to retrieve the data getting inside the list using get(index), but it doesn't work.
1 Answer 1
Looks like you have a ArrayList<LinkedHashMap<String, String>>
, not a ArrayList<SlotItem[]>
I want to get a simple ArrayList, not a LinkedHashMap. Because i want to retriever the information in this way
String storeId = slotsinfo.get(index).getStoreId();
Okay, then you need to fix however you are getting that data to have a ArrayList<SlotItem>
.
As it currently stands, you should be able to do
result.get(index).get("storeId");
EDIT
Try to get your JSON like this, making responseObject
an array of arrays
{
"responseObject": [
[
{ //SlotItem (date, string, int, boolean },
{ //SlotItem }
],
[
{ //SlotItem (date, string, int, boolean },
{ //SlotItem }
{ //SlotItem }
]
],
"messages" : "Hi Stackoverflow"
}
-
I update my post, maybe you can help me with this. I can't do The part of get("storeId"). Thank you So much.Dinorah Tovar– Dinorah Tovar10/11/2016 13:25:46Commented Oct 11, 2016 at 13:25
-
You really should reformat your JSON, if at all possible. Having keys of x0, x1,..., xn means you need an array. You do not show an array of arrays, you show a dictionary of key-values, where all values are arrays. Your current format requires you to do
responseObject.get("slot_0").get(index).get("storeId")
. If you did have an array of arrays, you could loop over all arrays ofresponseObject
in order. Currently, you'd have to loop over thekeySet
of the response objectOneCricketeer– OneCricketeer10/11/2016 13:40:39Commented Oct 11, 2016 at 13:40 -
Thats actually the problem, because I can't reformat the JSON, (Is an awful json that not even the way it should be) I will try to check the results of the loop, Thank you so muchDinorah Tovar– Dinorah Tovar10/11/2016 14:09:46Commented Oct 11, 2016 at 14:09