使用Twitter JSON响应

时间:2013-04-26 11:40:04

标签: python json python-2.7 twitter

我正在使用Twitter API和python,当我尝试合并我检索的JSON页面时,我遇到了问题。

为每个请求检索的JSON结构为:

{
  "previous_cursor": 0,
  "previous_cursor_str": "0",
  "next_cursor": 1333504313713126852,
  "users": [
        {
          "foo": "bar",
          "foo": "bar",
          "foo": "bar",
          "foo": "bar",
          "foo": "bar"
         },
         {
          "foo": "bar",
          "foo": "bar",
          "foo": "bar",
          "foo": "bar",
          "foo": "bar"
         },
         {
          "foo": "bar",
          "foo": "bar",
          "foo": "bar",
          "foo": "bar",
          "foo": "bar"
         }
     ],
     "next_cursor_str": "1333504313713126852"
}

我需要合并每个用户信息的一个列表中的所有数据。问题在于,当我这样做时,我得到了这个结构:

friends_list = [friends_list, raw_friends_list['users']]

[
    {"foo": "bar","foo": "bar"}
    {"foo": "bar","foo": "bar"}
    {"foo": "bar","foo": "bar"}
]
[
    {"foo": "bar","foo": "bar"}
    {"foo": "bar","foo": "bar"}
    {"foo": "bar","foo": "bar"}
]    

而不是:

[
    {"foo": "bar","foo": "bar"}
    {"foo": "bar","foo": "bar"}
    {"foo": "bar","foo": "bar"}
    {"foo": "bar","foo": "bar"}
    {"foo": "bar","foo": "bar"}
    {"foo": "bar","foo": "bar"}
]  

有没有人知道用python实现这个目的的正确方法?

此致

1 个答案:

答案 0 :(得分:0)

friends_list.extend(raw_friends_list['users'])