我是 JavaScript 新手,我正在尝试从文件中读取数据并将其保存在列表中,以便以后检索。就像是:
示例.json
{
"circles": [
{"x":14,"y":2,"z":4,"r":50},
{"x":14,"y":2,"z":4,"r":50}
]
}
我正在寻找的是:
var circle_list = []
circle_lst = some_function_which_reads_json_from_file('sample.json')
//Now circle list contains
circle_list = [
{"x":14,"y":2,"z":4,"r":50},
{"x":14,"y":2,"z":4,"r":50}
]
稍后我可以做类似的事情:
for (var i = 0; i <circle_list.lenght;i++){
//do osmething
}
我正在调查
$.getJSON("sample.json" , function(data){
//
});
但后来我知道这个调用是异步的......但我需要保持执行顺序。