Python: Saving API result into json file?

This question already has an answer here:

  • How do I write JSON data to a file? 10 answers

  • I'm assuming you have the data into a variable inside your code. So:

    You first need to transform this data into a json object (if you just add this list into an object, like "{'list':" + this_data + "}" you have a json!).

    So then you only need to get this json data and write it into a file:

        writeFile =open('file_name.json', 'w')
        writeFile.write(your_data)
        writeFile.close()
    

    Hope this might help you :)

    链接地址: http://www.djcxy.com/p/48690.html

    上一篇: json.dumps中的8个文本为UTF8,而不是\ u转义序列

    下一篇: Python:将API结果保存到json文件中?