Facebook API返回null,如何在Javascript中跳过它
如果没有返回空值,这段代码工作得很好。但我在测试期间注意到,如果任何值为null,那么它会抛出错误并中断脚本的其余部分 如果为null,我如何跳过该值,或将其设置为其他值Facebook API返回null,如何在Javascript中跳过它,javascript,facebook,null,facebook-fql,Javascript,Facebook,Null,Facebook Fql,如果没有返回空值,这段代码工作得很好。但我在测试期间注意到,如果任何值为null,那么它会抛出错误并中断脚本的其余部分 如果为null,我如何跳过该值,或将其设置为其他值 function fqlQuery(){ FB.api('/me', function(response) { var query = FB.Data.query('SELECT uid, first_name, last_name, email, se
function fqlQuery(){
FB.api('/me', function(response) {
var query = FB.Data.query('SELECT uid, first_name, last_name, email, sex, pic_square, timezone, birthday_date, current_location FROM user WHERE uid = me()', response.id);
query.wait(function(rows) {
fb_uid = rows[0].uid;
first_name = rows[0].first_name;
last_name = rows[0].last_name;
sex = rows[0].sex;
email = rows[0].email;
fb_pic_square = rows[0].pic_square;
timezone = rows[0].timezone;
birthday_date = rows[0].birthday_date;
current_city = rows[0].current_location.city;
current_country = rows[0].current_location.country;
$.ajax({
type: "POST",
url: "postdb.php",
data: "first_name=" + first_name + "&last_name=" + last_name + "&email=" + email + "&fb_uid=" + fb_uid + "&sex=" + sex + "&fb_pic_square=" + fb_pic_square + "&timezone=" + timezone + "&birthday_date=" + birthday_date + "¤t_city=" + current_city + "¤t_country=" + current_country,
success: function(msg){
alert( "Data Saved: " + msg );
}
});
});
});
提前谢谢
var foo = rows[0].foo || "";
如果行[0],将返回”
(空字符串)。foo
为空。我这样修复了它
if(rows[0].current_location != null){
current_city = rows[0].current_location.city || "";
current_country = rows[0].current_location.country || "";
}
我刚试过你的建议。仍然得到同样的结果。行[0]。当前_位置为空[在此错误上中断]当前_城市=行[0]。当前_位置。城市| |“”;如果当前位置不为空,则仅访问当前位置.city。