1

Can you please help me in parsing {"array" : ["123", "345", "567", "789"]} via Retrofit2.

I have tried this way,

ArrayList<String> array = new ArrayList<>(); 
public void setArray(ArrayList<String> array){
this.array = array;
}
public ArrayList<String> getArray(){
return this.array;
}
1
  • What is the error you are getting? Commented Nov 4, 2017 at 6:48

4 Answers 4

2

Change your getArray method like this

public ArrayList<String> getArray(){
    return this.array;
}

you forgot to return ArrayList

Sign up to request clarification or add additional context in comments.

Comments

0

u can use from gson library for parsing to json object or array like this:

JsonArray version = new JsonParser().parse(strResponse).getAsJsonArray();

Comments

0

To parse to array from retrofit:

@GET("methodThatReturnsArray")
Call<ArrayList<String>> methodThatReturnsArray();

now you have to call Synchronous would look like:

Call<ArrayList<String>> call = retrofitService.methodThatReturnsArray();
Response response = call.execute();
ArrayList<String> arrayOfStrings = response.body();

Happy coding!!

Comments

0

I don't know which converter you are using but for Strings, you can use Scalars in here . Hopefully it helps to you :)

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.