相关疑难解决方法(0)

如何将JSON数据写入文件?

我将JSON数据存储在变量中data.

我想将其写入文本文件进行测试,因此我不必每次都从服务器获取数据.

目前,我正在尝试这个:

obj = open('data.txt', 'wb')
obj.write(data)
obj.close
Run Code Online (Sandbox Code Playgroud)

我收到错误:

TypeError: must be string or buffer, not dict

如何解决这个问题?

python json

992
推荐指数
11
解决办法
134万
查看次数

在serve方法中将值转换为json。鹡鸰

我确实试图找到问题的答案,但不知道该怎么办。我发现了以下问题,但他们没有帮助我。问题1问题2文档

\n\n

我使用的不同函数得到了不同的值。有时None
\nTypeError: Object of type \'method\' is not JSON serializable
有时\nAttributeError: \'str\' object has no attribute \'status_code\'和\n而这个
\nTypeError: \'method\' object is not iterable

\n\n

但我仍然没有找到解决我的问题的解决方案。\n这是我的页面模型,它InlinePanel从另一个类获取一些数据:

\n\n
class ScreencastPage(Page):\n    content_panels = Page.content_panels + [\n        InlinePanel(\n            \'groupstage_screencast_relationship\', label="Choose Teams",\n            panels=None, max_num=2),\n    ]\n\n    parent_page_types = [\'home.HomePage\']\n\n    def matches(self):\n        matches = [\n            n.match for n in self.groupstage_screencast_relationship.all()\n        ]\n\n        return matches\n\n    def serve(self, request):\n        if request.is_ajax():\n            # TODO Convert self.mathes …
Run Code Online (Sandbox Code Playgroud)

wagtail

0
推荐指数
1
解决办法
1059
查看次数

标签 统计

json ×1

python ×1

wagtail ×1