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: "testing@gmail.com"
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: ""
}
}
Vikasdeep Singh
  • 20,983
  • 15
  • 78
  • 104
vignesh
  • 25
  • 1
  • 7

4 Answers4

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);
aravindkanna
  • 663
  • 1
  • 7
  • 25
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.

kgandroid
  • 5,507
  • 5
  • 39
  • 69
  • Give the full path of the image nad not just images/89159094355efdcebb3c568.81451258.jpg,it will work definitely – kgandroid Sep 09 '15 at 10:21
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

Community
  • 1
  • 1
Viks
  • 1,510
  • 4
  • 22
  • 50
1

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

here is good tutorial

SRB Bans
  • 3,096
  • 1
  • 10
  • 21