Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 使用jQuery将JSON中的元素转换为html不起作用_Javascript_Json - Fatal编程技术网

Javascript 使用jQuery将JSON中的元素转换为html不起作用

Javascript 使用jQuery将JSON中的元素转换为html不起作用,javascript,json,Javascript,Json,我使用下面的代码从这个JSON中获取一些元素,但似乎什么都不起作用。有人知道我做错了什么吗?(我花了很长时间想弄明白) 使用JavaScript控制台。阅读它给你的错误 未捕获的语法错误:意外标记 终止语句,而不是表达式。删除来自此.weather[0]。日期 如果你解决了这个问题,那么你会得到: XMLHttpRequest无法加载http://free.worldweatheronline.com/feed/weather.ashx?q=Stockholm&format=json&num_o

我使用下面的代码从这个JSON中获取一些元素,但似乎什么都不起作用。有人知道我做错了什么吗?(我花了很长时间想弄明白)


使用JavaScript控制台。阅读它给你的错误

未捕获的语法错误:意外标记

终止语句,而不是表达式。删除
来自
此.weather[0]。日期

如果你解决了这个问题,那么你会得到:

XMLHttpRequest无法加载
http://free.worldweatheronline.com/feed/weather.ashx?q=Stockholm&format=json&num_of_days=2&key=e8536d3a52101433121710. 起源http://fiddle.jshell.net
是访问控制允许原点不允许的


这是

如果您的请求os a cross domain=url不是来自您的域,您应该设置跨域标志或使用jsonp。

您可以在浏览器中打开JavaScript控制台。在Chrome中,它位于工具>开发者工具下。我如何设置跨域标志?请阅读:这是一个小插件,可以帮助您完成这项工作
$(document).ready(function() {

$.getJSON('http://free.worldweatheronline.com/feed/weather.ashx?q=Stockholm&format=json&num_of_days=2&key=e8536d3a52101433121710', function(Wdata) {
                $.each(Wdata.data, function() {

                $('<div id="test"></div>').append(

                        this.weather[0].date;

                        ).appendTo('body');

                  });
    });
});
<!doctype html>
<html lang="se">
    <head>
        <meta charset="utf-8" />
        <title>Title of This Web Page</title>
        <script src="scripts\jquery-1.8.2.js" type="text/javascript"></script>
        <script src="scripts\js.js" type="text/javascript"></script>
    </head>

    <body>
              <div id="test">
              </div>
    </body>

</html>
{

    "data": {
        "current_condition": [ … ],
        "request": [ … ],
        "weather": [
            {
                "date": "2012-10-17",
                "precipMM": "0.8",
                "tempMaxC": "11",
                "tempMaxF": "51",
                "tempMinC": "8",
                "tempMinF": "46",
                "weatherCode": "119",
                "weatherDesc": [
                    {
                        "value": "Cloudy"
                    }
                ],
                "weatherIconUrl": [
                    {
                        "value": "http://www.worldweatheronline.com/images/wsymbols01_png_64/wsymbol_0003_white_cloud.png"
                    }
                ],
                "winddir16Point": "SW",
                "winddirDegree": "224",
                "winddirection": "SW",
                "windspeedKmph": "27",
                "windspeedMiles": "17"
            },
            { … }
        ]
    }

}