【问题标题】:How to call json file data in my html file ? below is my json file structure如何在我的 html 文件中调用 json 文件数据?下面是我的 json 文件结构
【发布时间】:2016-09-19 02:53:16
【问题描述】:

[ { “身份证”:2, "name": "冰雕", “价格”:12.50, },

{ “身份证”:3, "name": "一只蓝老鼠", “价格”:25.50, } ]

【问题讨论】:

标签: javascript html json


【解决方案1】:

$url= "http://nominatim.openstreetmap.org/reverseformat=json&lat=12.9166&lon=77.6101&zoom=18&addressdetails=1";

$json = @file_get_contents($url); $data = json_decode($json);

如何从此链接接收数据。

【讨论】:

    【解决方案2】:

    Json 对象:

       var data = [ 
                    {  
                      "id": 2, 
                      "name": "An ice sculpture", 
                      "price": 12.50 
                    },
                    {
                      "id": 3, 
                      "name": "A blue mouse", 
                      "price": 25.50 
                    } 
                  ];
    

    迭代对象的每个属性:

        var htmlContent = '';
    
        for ( var key in data ) {
            htmlContent += '<div class="container">';
            htmlContent += '<p> Name: ' + data[key].name + '</p>';
            htmlContent += '<p> Price: ' + data[key].ptice + '</p>';
            htmlContent += '</div>';
        }
    
        $('body').append(htmlContent);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-08-14
      • 1970-01-01
      • 1970-01-01
      • 2015-11-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-04-07
      相关资源
      最近更新 更多