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.

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"
}
Sign up to request clarification or add additional context in comments.

3 Comments

I update my post, maybe you can help me with this. I can't do The part of get("storeId"). Thank you So much.
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
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

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.