从json解析图像 [英] parse image from json

查看:207
本文介绍了从json解析图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

http://api.wunderground.com/ api / 102376e7c0e1c995 / geolookup / conditions / q / IA / Cedar_Rapids.json

这是.json文件,
在这个json文件中有一个给出天气图标条件的变量。
我希望看到使用ID将此图片放在HTML中。

This is .json file to get the weather condition in Cedar Rapids, IA. In this json file there is variable that give the weather icon condition. I want to see put this image in html using ID's.

<html>
<head>
<script src="http://code.jquery.com/jquery-1.8.3.min.js"></script>
</head>
<body>
<h1 id='meteo'></h1>
<script type="text/javascript">
jQuery(document).ready(function($) {
    var state = 'CA';
    var city = 'San_Francisco';
    var URL = 'http://api.wunderground.com/api/102376e7c0e1c995/geolookup/conditions/q/' + state + '/' + city + '.json';
    $.ajax({ 
        url : URL, 
        dataType : "jsonp", 
        success : function(parsed_json) { 
            var location = parsed_json['location']['city']; 
            var temp = parsed_json['current_observation']['temperature_string'];
            var wicon = parsed_json['current_observation']['icon_url'];
            $("#meteo").text(temp); 
        }
    });
}); 
</script>
</body>
what can i do
</html>


推荐答案

作为脚本的最后一行,添加:

As the last line of your script, add:

$("#meteo").append('<img src="' + wicon + '"/>");

这篇关于从json解析图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆