选择第一个JSON数组+按字过滤

时间:2012-03-30 06:54:32

标签: jquery facebook json filter

我正在使用jQuery创建一个Facebook页面,我想过滤帖子。但我似乎无法弄清楚如何。我对jQuery不是很有经验,但学习。

所以我想用#hashkp过滤掉#weekhap这个词,所以所有者更容易管理Facebook上的所有内容。这甚至可能吗?我正在使用此代码:

function fbFetchWeekhap(){
  var url = "https://graph.facebook.com/reindersrobin/posts&access_token=AAAE6AYdEq9sBALPKSIgPUDrdQIy2aHZBQSQI9DuhY1yx9z1ZC1p8TVLTCCIuZBZAgw1ann9iyghVGPLwsTRwOJZAC8a6M53YZD";  
    $.getJSON(url,function(json){
            console.log(json)   
                $.each(json.data,function(i,fb){
                    var html = fb.message;
                $("#weekhap").html(html);     
                });
            });  
};

Facebook JSON正在产生这个:

"data": [
    {
      "id": "401455409880061_417873164904952", 
      "from": {
        "name": "ReindersRobin", 
        "category": "Bar", 
        "id": "401455409880061"
      }, 
      "message": "#weekhap", 
      "actions": [
        {
          "name": "Comment", 
          "link": "http://www.facebook.com/401455409880061/posts/417873164904952"
        }, 
        {
          "name": "Like", 
          "link": "http://www.facebook.com/401455409880061/posts/417873164904952"
        }
      ], 
      "privacy": {
        "description": "Public", 
        "value": "EVERYONE"
      }, 
      "type": "status", 
      "created_time": "2012-03-30T05:58:09+0000", 
      "updated_time": "2012-03-30T05:58:09+0000", 
      "comments": {
        "count": 0
      }, 
      "is_published": true
    }, 

1 个答案:

答案 0 :(得分:0)

function fbFetchWeekhap( filter_word ){ 
    var url = "https://graph.facebook.com/reindersrobin/posts&access_token=ACCESS_TOKEN";
    $.getJSON(url,function(json){ 
        console.log(json);
        $.each(json.data,function(i,fb){
            var html = fb.message;
            if( fb.messsage == filter_word){ # filter here
                $("#weekhap").append('<p>'+html+'</p>');
            }
        }); 
    });
};

使用fbFetchWeekhap('#weekhap');