我已经仔细研究了为什么会发生这种情况。我有一个脚本,它使用 AJAX 获取本地 JSON 文件并将它们合并在一起,以便以后可以在 HTML 表中显示数据。
该脚本可以很好地在 Chrome 控制台中显示对象。但我无法访问特定元素,例如“object.country”。关于如何解决这个问题的任何帮助?
控制台输出(缩短):
(3) [Array(244), "success", {…}]
0: Array(244)
[0 … 99]
0: {country: "Afghanistan", city: "Kabul", continent: "Asia", costline: 0, currency_name: "Afghanistan Afghani", …}
脚本
function onLoad() {
$.when(
$.ajax({
url: "./country-objects/country-by-capital-city.json",
type: "GET",
dataType: 'JSON'
}),
$.ajax({
url: "./country-objects/country-by-continent.json",
type: "GET",
dataType: 'JSON'
}),
$.ajax({
url: "./country-objects/country-by-costline.json",
type: "GET",
dataType: 'JSON'
}),
$.ajax({
url: "./country-objects/country-by-currency-name.json",
type: "GET",
dataType: 'JSON'
}),
$.ajax({
url: "./country-objects/country-by-flag.json",
type: "GET",
dataType: 'JSON'
}),
$.ajax({
url: "./country-objects/country-by-domain-tld.json",
type: "GET",
dataType: 'JSON'
})).then(function (res1, res2, res3, res4, res5, res6) {
const object = $.extend(true, res1, res2, res3, res4, res5, res6);
console.log(object);
})
}
- 编辑 -
每个 JSON 文件的示例对象(每个文件的第一个条目)。以相同顺序 az 的所有文件:
// /country-objects/country-by-capital-city.json
{
"country": "Afghanistan",
"city": "Kabul"
}
// /country-objects/country-by-continent.json
{
"country": "Afghanistan",
"continent": "Asia"
}
// /country-objects/country-by-costline.json
{
"country": "Afghanistan",
"costline": 0
}
// /country-objects/country-by-currency-name.json
{
"country": "Afghanistan",
"currency_name": "Afghanistan Afghani"
}
// /country-objects/country-by-flag.json
{
"country": "Afghanistan",
"flag_base64": "data:image\/svg+xml;base64,PHN2ZyB4bWxucz0ia......"
}
// /country-objects/country-by-domain-tld.json
{
"country": "Afghanistan",
"tld": ".af"
}
// Goal, continue for each country
{
"country": "Afghanistan",
"city": "Kabul",
"continent": "Asia",
"costline": 0,
"currency_name": "Afghanistan Afghani",
"flag_base64": "data:image\/svg+xml;base64,PHN2ZyB4bWxucz0ia......",
"tld": ".af"
},