1

I have a problem with my retofit response. I get response like this :

{
"data": [
           [
               "Admin",
               "Adress Street 26"
           ],
           [
               "Users",
               "Adress Street 27"
           ]
       ]
}

My Pojo is like this :

package com.example;

import java.util.List;
import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;

public class Example {

@SerializedName("data")
@Expose
private List<List<String>> data = null;

public List<List<String>> getData() {
return data;
}

public void setData(List<List<String>> data) {
this.data = data;
}

}

How i can get two this value? In this case, I use retrofit for my android app. I have search for two days. Can anyone help me? Thx

5
  • your object class is perfect !! Just call for the object class Example , thats it !! Commented Mar 30, 2018 at 3:10
  • I thinks reponse string isn't json format. Commented Mar 30, 2018 at 3:13
  • if it is not json format, i can't pass the validator dude Commented Mar 30, 2018 at 4:11
  • @SantanuSur thanks man, I have do it, but can I call one by one data from that json? if I call that object, I get "Admin","Adress Street 26". can I just get "Admin" or Adress Street"? Commented Mar 30, 2018 at 4:29
  • Firstly Make List<List<String>> mainList = example.getData(); After that for getting list from each position enter List<String> firstList = mainList.get(0); List<String> secondList = mainList.get(1); and so on. you can take it in loop. After getting first list when you call firstList.get(0) then you will get admin only and when you call firstList.get(1) then you will get Adress Street 26. Commented Mar 30, 2018 at 4:39

1 Answer 1

1

Firstly Make

List<List<String>> mainList = example.getData();

After that for getting list from each position enter

List<String> firstList = mainList.get(0);
List<String> secondList = mainList.get(1); 

and so on, you can take it in a loop. After getting first list when you call firstList.get(0) then you will get admin only and when you call firstList.get(1) then you will get "Adress Street 26".

String adminStr = firstList.get(0);
String addressStr = firstList.get(1);
Sign up to request clarification or add additional context in comments.

Comments

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.