如何將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
相關文章
相關標籤/搜索