如何显示此json图像

时间:2012-02-19 15:41:33

标签: android json image url

我一直在尝试几种显示我的json图像的方法,但我的解决方案从未成功过。

我已经解析了我的json,我得到了回复。

但是包括respose是我需要在我的应用程序中显示的图像。

接收图像为:“http://media.rightmove.co.uk/31k/30471/29462938/30471_FLE100159_IMG_00_0002_max_200x1 38.jpg”这只是字符串。我的数据库中有以下图像。

如何在我的应用中显示这些图片?

![Parsed images] [1]

提前致谢

以下代码。

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");
    }
}

非常感谢

2 个答案:

答案 0 :(得分:0)

试试我的朋友:) 解析你的json并获取URL,然后将它们放在方法中 https://asantoso.wordpress.com/2008/03/07/download-and-view-image-from-the-web/

答案 1 :(得分:0)

jSON实际上不包含图像,它包含图像的链接。如果将这些URL提供给WebView或浏览器,您将看到图像。

试试这个:

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

这会将图像绘制到webview中。您可以像我上面那样以xml或编程方式定义您的webview。

相关问题