JavaScript中获取JSON文件中的数据

时间:2025-03-23 17:16:02

1. 使用Ajax方式获取

$.ajax({
     type: "get",
     url: "json/",
     dataType: "json",
     async: false,
     success: function(data) {
          console.log(data.total);
     }
});

2. 使用get方式获取

$.get("json/", function(data) {
 	console.log(data.total);
});

3. 使用 getJSON 方式获取

$.getJSON("json/", function(data)  {
     console.log(data.total);
})

以上方式获取到的数据都是 JSON 格式的数据,无需转换,即可使用!!!