jQuery检查返回的JSON是否为NULL

ben*_*e89 3 null jquery json

我有这个返回的JSON:

results: Array[15]
0: Object
created_at: "Wed, 10 Aug 2011 22:45:36 +0000"
from_user: "CriisBellaFlor"
from_user_id: 360990380
from_user_id_str: "360990380"
geo: null
Run Code Online (Sandbox Code Playgroud)

我正在使用此代码循环它:

var twitterUrl='http://search.twitter.com/search.json?callback=?&q=';
                query='cinema';
                $.getJSON(twitterUrl+query,function(json){
                    console.log(json);
                    $.each(json.results,function(i,tweet){
                        if(tweet.iso_language_code == 'en'){
                            if(tweet.geo === 0){
                                $(cinemas).append('<img src="'+tweet.profile_image_url+'" width="48" height="48" />'+tweet.text+'<br />');
                            } else {
                                $(cinemas).append('<img src="'+tweet.profile_image_url+'" width="48" height="48" />'+tweet.text+'Coordinates:' + tweet.geo.coordinates[0] + ' + ' + tweet.geo.coordinates[1] + '<br />');
                            }

                        }
                    });
                });
Run Code Online (Sandbox Code Playgroud)

所以我想确定的是,如果"geo"为null,不要尝试显示坐标,如果有什么东西,则显示它们.

但我得到这个错误:

Uncaught TypeError: Cannot read property 'coordinates' of null
Run Code Online (Sandbox Code Playgroud)

Jac*_*iuk 5

试试看

if(tweet.geo === null){
Run Code Online (Sandbox Code Playgroud)

BTW,===意味着比较检查也是变量的类型