1

I am getting json response which includes image string also. How to decode the image and how to set in ImageView?

{
success: true
customer: {
customer_id: 93
firstname: "vigneshtesting"
lastname: ""
email: "[email protected]"
telephone: 8189968996
fax: ""
image: "images/89159094355efdcebb3c568.81451258.jpg"
salt: "222ef72b3"
password: "8e61e0255f99ede9c2eb2290347285c5a6552012"
newsletter: ""
customer_group_id: ""
status: ""
date_modified: "0000-00-00 00:00:00"
abbr: ""
grpname: ""
description: ""
approve: ""
disp_comp: ""
comp_no: ""
disp_tax: ""
tax_id: ""
sortorder: ""
banip: ""
}
}
3
  • 1
    1. Parse your json and get the url. 2. Download the image and set the image to imageview Commented Sep 9, 2015 at 9:09
  • 1
    @vignesh Use Image loading libraries like Glide, Universal Image Loader etc., Commented Sep 9, 2015 at 9:10
  • I will do..@Raghunandan @b1izzard Commented Sep 9, 2015 at 9:18

4 Answers 4

3

First you need to parse the JSON.

JSONObject jsonObject = <your-object>;
String image = jsonObject.getString("image");

Now you have the image url as a string in the string object 'image'. You have to load the image in this url to the target imageview. For that you can use Picasso. A clear description of how to use that is mentioned there. You can directly use this string for that purpose as shown below.

Picasso.with(context).load(image).into(imageView);
Sign up to request clarification or add additional context in comments.

Comments

2

Parse the image url from json and get the image as bitmap:

URL url = new URL("http://....");
Bitmap image = BitmapFactory.decodeStream(url.openConnection().getInputStream());

Then set the image in imageview as:

imageview.setImageBitmap(image);

Note:use a asynctask to download the image from the url.

1 Comment

Give the full path of the image nad not just images/89159094355efdcebb3c568.81451258.jpg,it will work definitely
1

Parse your JSON and get the url and use any library to download like : Picaso library

here is good tutorial

Comments

1

Parse your json to get image url. To show image from url best way is to use Picasso library In which you can directly put your image Url and it also help to cache the image.

Read this Documentation for picasso.

Other helpful libraries are:

1) Android-Universal-Image-Loader

2) ion

Or if you want to get bitmap from url then see here

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.