问题:
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: 目前,我正在尝试:
obj = open('data.txt', 'wb')
obj.write(data)
obj.close
And am receiving the error: 并收到错误:
TypeError: must be string or buffer, not dict
How to fix this? 如何解决这个问题?
解决方案:
参考一: https://stackoom.com/question/peCb/如何将JSON数据写入文件参考二: https://oldbug.net/q/peCb/How-do-I-write-JSON-data-to-a-file
来源:oschina
链接:https://my.oschina.net/stackoom/blog/4316073