Reputation: 25
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: ""
}
}
Upvotes: 1
Views: 5350
Reputation: 683
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);
Upvotes: 3
Reputation: 5595
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.
Upvotes: 2
Reputation: 1574
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
Upvotes: 1
Reputation: 3134
Parse your JSON and get the url and use any library to download like : Picaso library
Upvotes: 1