将 Tweepy 状态对象转换为 JSON [英] Convert Tweepy Status object into JSON

查看:51
本文介绍了将 Tweepy 状态对象转换为 JSON的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Tweepy 下载推文.我有一个程序,然后将实际的 Status 对象以文本形式写入文件.如何将其转换为 JSON,或将此对象重新导入 Python?我尝试使用 JSON 库进行编码,但 Status 不是 JSON 可序列化的.

解决方案

tweepy 本身的 Status 对象不是 JSON 可序列化的,但它有一个 _json 属性,其中包含JSON 可序列化响应数据.例如:

<预><代码>>>>status_list = api.user_timeline(user_handler)>>>状态 = status_list[0]>>>json_str = json.dumps(status._json)

I'm using Tweepy to download tweets. I have a program that then writes the actual Status object to a file in text form. How do I translate this into JSON, or import this object back into Python? I've tried using the JSON library to encode, but Status is not JSON serializable.

解决方案

The Status object of tweepy itself is not JSON serializable, but it has a _json property which contains JSON serializable response data. For example:

>>> status_list = api.user_timeline(user_handler)
>>> status = status_list[0]
>>> json_str = json.dumps(status._json)

这篇关于将 Tweepy 状态对象转换为 JSON的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆