I have a JSON
string, say a name and a Url . I need to extract name into the TextView
and extract and display image in ImageView
.
Belo
You could extract the image name and url like this
public static final String JSON_STRING="{\"WebImages\":{\"Imagename\":\"image_name\",\"imageurl\":http://www.example.com/image/example.png}}";
JSONObject jsonObject = new JSONObject(JSON_STRING);
JSONObject webImages = jsonObject.getJSONObject("WebImages");
String imageName = webImages.getString("Imagename");
String imageUrl = webImages.getString("imageurl");
Now, you have the imageName and the imageUrl. You can easily set the text doing something like myTextView.setText(imageName)
. For loading the image into ImageView, I suggest using the Picasso library. It is extremely easy to use. All you need is one line of code, which would look like
Picasso.with(context).load(imageUrl).into(imageView);