Loading local JSON file

前端 未结 23 1588
悲哀的现实
悲哀的现实 2020-11-22 01:28

I\'m trying to load a local JSON file but it won\'t work. Here is my JavaScript code (using jQuery):

var json = $.getJSON("test.json");
var data = e         


        
23条回答
  •  北海茫月
    2020-11-22 01:38

    $.ajax({
           url: "Scripts/testingJSON.json",
               //force to handle it as text
           dataType: "text",
                success: function (dataTest) {
    
                    //data downloaded so we call parseJSON function 
                    //and pass downloaded data
                    var json = $.parseJSON(dataTest);
                    //now json variable contains data in json format
                    //let's display a few items
                    $.each(json, function (i, jsonObjectList) {
                    for (var index = 0; index < jsonObjectList.listValue_.length;index++) {
                          alert(jsonObjectList.listKey_[index][0] + " -- " + jsonObjectList.listValue_[index].description_);
                          }
                     });
    
    
                 }
      });
    

提交回复
热议问题