0

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.

OneCricketeer
193k20 gold badges145 silver badges275 bronze badges
asked Oct 10, 2016 at 16:19

1 Answer 1

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"
}
answered Oct 10, 2016 at 16:24
3
  • I update my post, maybe you can help me with this. I can't do The part of get("storeId"). Thank you So much. Commented 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 of responseObject in order. Currently, you'd have to loop over the keySet of the response object Commented 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 much Commented Oct 11, 2016 at 14:09

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.