如何将JSON数据写入文件? - How do I write JSON data to a file?

问题:

I have JSON data stored in the variable data . 我将JSON数据存储在变量data 服务器

I want to write this to a text file for testing so I don't have to grab the data from the server each time. 我想将其写入文本文件进行测试,所以没必要每次都从服务器获取数据。 测试

Currently, I am trying this: 目前,我正在尝试: this

obj = open('data.txt', 'wb')
obj.write(data)
obj.close

And am receiving the error: 并收到错误: spa

TypeError: must be string or buffer, not dict .net

How to fix this? 如何解决这个问题? code


解决方案:

参考一: https://stackoom.com/question/peCb/如何将JSON数据写入文件
参考二: https://oldbug.net/q/peCb/How-do-I-write-JSON-data-to-a-file
相关文章
相关标签/搜索