我正在尝试从此 JSON 文件解析城市
http://api.crunchbase.com/v/1/company/airbnb.js
这就是我解析其他数据的方法并且有效(有效!):
$.ajax({
url: "http://api.crunchbase.com/v/1/company/airbnb.js",
dataType: 'jsonp',
success: function(results){
var number_of_employees = results.number_of_employees;
var founded_month = results.founded_month;
var founded_year = results.founded_year;
$('#number_of_employees').append(number_of_employees);
$('#founded').append(founded_month + '/' + founded_year);
}
});
但是,这不起作用:
var location = results.city;
谢谢!
最佳答案
可能有多个办公室,但要获得第一个办公室,您可以通过以下方式访问它:
var office_city = results.offices[0].city;
您可能想检查这些字段是否确实存在......这里有一些更多的防御性编程:
if (typeof(results.offices) == 'object' && results.offices.length > 0 && results.offices[0].city)
{
var office_city = results.offices[0].city;
}
关于jquery - 如何从此 JSON 文件解析城市,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6701708/