0

I am developing android listing images app where I got array from server side. But I have issue to read array or don't know how to get it.

Below array i got from server API call:

{"lists":["http:\/\/xyz.com\/projects\/photo\/birthday\/1.jpg","http:\/\/xyz.com\/projects\/photo\/birthday\/3.jpg","http:\/\/xyz.com\/projects\/photo\/birthday\/4.jpg"],"Status":"1"}

How to read it and display images in loop.

Thanks

1
  • Do you always want to show the same number of pictures or are you going to use a ListView with a dynamic number of images? Commented Oct 3, 2015 at 11:30

1 Answer 1

1

If you are using gson library for parsing json respose then you could simply write a separate class like this

public class ImageResponse{
    public String Status;
    public List<String> lists;
}

NOTE: when creating a class the object names of the class should match with the tag names from the server..

Then using gson

 ImageResponse detail = (new Gson()).fromJson(
                    response.toString(), ImageResponse.class);

where response is your response from the server

now u can access the list like

List<String> images =details.lists;

Now you have all the images in the list form, you can load the images using Picasso[lets say in a listview]

Picasso.with(context).load(images[0]).into(imageView);

For using this you should add GSON library to your dependency in your app gradle

 compile 'com.google.code.gson:gson:2.2.4'

There are many other method too, feel free to search and find out may be there will be more optimized code than this..

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.