How can I display this json image

2019-09-12 06:29发布

I have been trying several ways of displaying my json images but my solutions never succeded.

I have parsed my json and I'm getting the response.

However included the respose is an image which I need to display in my app.

Recieving the image as :"http: //media.rightmove.co.uk/31k/30471/29462938/30471_FLE100159_IMG_00_0002_max_200x1‌​38.jpg" which is just string.I have these below images in my database.

How can I display these image in my app?

![Parsed images][1]

Thanks in advance

below code.

protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

    JSONParser prop = new JSONParser();
    JSONObject json = prop.getJSONFromUrl(url);
    try{
    properties = json.getJSONArray(TAG_PROPERTY);
    for (int i = 0; i < properties.length(); i++) {
        JSONObject c = properties.getJSONObject(i);
        String photoThumbnailUrl = c.getString(TAG_PHOTOS);             

    // load image view control
    imgView = (ImageView) findViewById(R.id.imgView);

    // grab image to display
    try {
        imgView.setImageDrawable(grabImageFromUrl(photoThumbnailUrl));


    } catch (Exception e) {
        txtUrl.setText("Error: image not grabed");
    }
   }
    }catch (Exception ex) {
    txtUrl.setText("Error: Properties not recieved");
    }
}

Many thanks

2条回答
你好瞎i
2楼-- · 2019-09-12 06:45

Try that my friend :) Parse your json and take the URL and then put them us URL in the method https://asantoso.wordpress.com/2008/03/07/download-and-view-image-from-the-web/

查看更多
Emotional °昔
3楼-- · 2019-09-12 06:49

The jSON doesn't actually contain the images, it contains links to the image. If you feed those URLs into a WebView or Browser, you will see the images.

try this:

String x = <URL of image, pulled out of JSON object>
Webview wv = new WebView(this);
wv.loadURL(x);

this will draw the image into the webview. You can define your webview in xml or programatically as I did above.

查看更多
登录 后发表回答