我想將Tweepy api.trends_location(woeid)
調用的結果轉換爲字典(或字典的字典),所以我可以使用這些值(真的,我想結束一個「名稱」值的字典)。 Tweepy文檔說結果是'JSON對象'(see here),但是當我檢索它時,type(retrieved)
的計算結果爲list
。果然,retrieved
有一個len
的1,和retrieved[0]
給我一個單一的項目:
[{'trends': [{'url': 'http://search.twitter.com/search?q=%23questionsidontlike', 'query': '%23questionsidontlike', 'events': None, 'promoted_content': None, 'name': '#questionsidontlike'}, ], (more of the same), 'created_at': '2011-01-31T22:39:16Z', 'as_of': '2011-01-31T22:47:47Z', 'locations': [{'woeid': 23424977, 'name': 'United States'}]}]
。轉換tweepy JSON對象爲字典
我可以叫json.dumps
,這將給一個很好的格式表示,但這是沒多大用的我,json.loads
給我:__init__() got an unexpected keyword argument 'sort_keys'
我應該如何進行?
鏈接到全碼:https://gist.github.com/805129
Python中的JSON對象實際上是用`list`和`dict`對象表示的。 `dict`用於對象,`list'用於數組。你究竟想要做什麼? – thkala 2011-01-31 23:21:05
我明白,但是一個成員的列表,這是整個結果沒有太大的用處,在這種情況下。我想將'name'的值提取到他們自己的列表中。 – urschrei 2011-01-31 23:28:23