【问题标题】:how to display multiple json data in html如何在html中显示多个json数据
【发布时间】:2015-07-24 20:33:01
【问题描述】:

我正在使用天气 api,我的目的是将 json 数据显示到简单的 html 视图中......

问题是(也许)上面的脚本根本不起作用,甚至警告,如果我做错了,请有人指导......

脚本和 html

<div id ="fj"></div>

$(document).ready(function() {
  var teams;
  $.getJSON("http://api.openweathermap.org/data/2.5/forecast/daily?lat=33.5689&lon=72.6378&cnt=10", function(dataDD) {
    //do some thing with json  or assign global variable to incoming json.
    var tasks = $.parseJSON(dataDD.city);
    alert(tasks);
    //alert('empLoggedId');
    $.each(tasks, function(key, value) {
      $("#fj").append(data.weather.description);

    });
  });
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<div id="fj"></div>

任何类型的 hep 或参考将不胜感激 感谢您的宝贵时间

【问题讨论】:

  • 你需要提供更多细节,可能还有一个 jsFiddle,否则我认为你会得到一些反对票。
  • @Suhail 你能指出你得到错误的确切行吗?
  • JSON 文件中有很多数据。如果你清楚你需要什么,那么我可以发布一个答案。
  • @根本没有控制台错误,这意味着我们遇到了属性访问问题,现在可以正常工作了,感谢大家的帮助

标签: javascript jquery json asp.net-web-api


【解决方案1】:

给你,http://jsfiddle.net/9c2tb8xk/

我不确定您要列出什么,但我认为这就是您想要的。

$(document).ready(function() {
  var teams;
  $.getJSON("http://api.openweathermap.org/data/2.5/forecast/daily?lat=33.5689&lon=72.6378&cnt=10", function(dataDD) {
    //$.getJson parses for you, dont try to parse it again.
    var tasks = dataDD.list //tasks is list property of dataDD
    $.each(tasks, function(key, value) { //for each value in list will be in value
      $("#fj").append(value.weather[0].description); //I used the value as a specific item from list. 
    });
  });
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<div id ="fj"></div>

【讨论】:

  • 是的,我认为他想在 json 中迭代列表!
  • @Ahmet 很抱歉迟到了,我遇到了网络问题...干杯
猜你喜欢
  • 2022-11-11
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-11-09
  • 2019-05-20
  • 2019-01-25
  • 1970-01-01
相关资源
最近更新 更多