H_MZ 2017-05-10 06:32 采纳率: 0%
浏览 46

加载多个JSON对象

I am trying to load multiple JSON object from one file, but my attempts failed. Here is my code which run to error when I tried to load .JSON file.

$(document).ready(function(){
    $.ajax({
        url: "..data.json", 
        method: "GET", 
        success: function(data) {
           // do something
        },  
        error: function(data) {
            console.log('error');
        }
    });
  });

The file format what I am trying to load is the following:

[{"id_first":"1","data_first":"1"},{"id_first":"2","data_first":"2"}] [{"id_second":"1","data_second":"1"},{"id_second":"2","data_second":"2"}]

Is there any solultion for this problem? Thanks for helps in advance!

  • 写回答

1条回答 默认 最新

  • 笑故挽风 2017-05-10 06:39
    关注

    i think you need to change the json schema like this at the backend.

    [
     [{
        "id_first": "1",
        "data_first": "1"
      }, {
        "id_first": "2",
        "data_first": "2"
     }],
     [{
        "id_second": "1",
        "data_second": "1"
     }, {
        "id_second": "2",
        "data_second": "2"
     }]
    ]
    

    it more easier for you to process the data.

    评论

报告相同问题?