3

我正在使用 jQuery 解析来自 Twitter 的 JSON 结果。

然后,我将对返回的结果进行检查,以查看它们是否包含双引号。

$.getJSON(url + query, function(json) {
    $.each(json.results, function(i, tweet) {
        var result = tweet.text.indexOf('"');
        if(result != -1) {
             $("#results").append('<p>' + tweet.text + '</p>');
        }
    });
});

结果始终为 -1。即使返回的推文包含双引号。

我也尝试过使用: indexOf("\"");这也不起作用。

知道我可能做错了什么吗?这可能是编码问题吗?

4

2 回答 2

3

The Twitter API returns double-quotes as &quot;. As an example, check out the response for this query: http://search.twitter.com/search.json?q=foo.

So, you'll need to use tweet.text.indexOf('&quot;') instead.

于 2011-05-12T19:13:38.607 回答
1

Yes, check encoding. %22, maybe? Otherwise, console shows that tweet.text has the quotes, right? I can see no reason why your code wouldn't work.

于 2011-05-12T19:11:06.960 回答