使用getJSON从远程json收集keyvalues

时间:2014-09-20 07:27:12

标签: javascript sql json

我对javascript不是很熟悉我希望你能告诉我如何解决这个问题。我将数据库表作为json格式的输出,这是一个示例:

[{" ID":" 11"" NOMBRE":"萨伯"" direccion&#34 ;: "智利11"," telefono":" 4270044"," apertura":" 09:00:00", " cerradura":" 20:00:00""提示":" sanguche"" votos":& #34; 3"," calificacion":" 6.00"," actualizacion":" 2014-09-15 21:59:43& #34;},{" ID":" 12"" NOMBRE":" OtroComp"" direccion" :" San Martin 22"," telefono":" 456789"," apertura":" 10:00:00&#34 ;" cerradura":" 20:00:00"," Hint":" papa al horno y pollo"," votos":" 2"" calificacion":" 4.00"" actualizacion":" 2014-09- 15 21:42:01"}]

这是我在javascript中的代码

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script type="text/javascript" >
var gclaData = 'http://blablabla.com/jsonpuller.php?callback=?';
$.getJSON(gclaData,function(data){
event = 'Next Event Dates<br><br>';

$.each(data.ID, function(j,ID ){

    event += '<div class="eventHolder">'; 
    event += '<div class="eventID">'+ data.ID +"</div>";
    event += '</div>';
    event +='<hr>';
});
$('#output').html(event);
});
</script>

页面中没有显示任何内容:-(如何显示所有ID?

1 个答案:

答案 0 :(得分:0)

尝试使用此更改$.each的一部分;

$.each(data, function(key){
    event += '<div class="eventHolder">'; 
    event += '<div class="eventID">'+ data[key].ID +"</div>";
    event += '</div>';
    event +='<hr>';
});