简体   繁体   中英

Writing JSON data to file in python

I'm not quite sure on how you write a JSON so can you please help me, i'm trying to make this with JSON in python . Here's the pseudo-code

binary_students = json(students)

write_to_the_file_system(binary_students)

I'm not quite understanding it, can someone help me please.

You can use a dictionary for storing Json data like this:

>>> dict = {'Student1':'x1','Student2':'x2'}

and then use the json library

>>> import json
>>> with open('data.txt', 'w') as outfile:
    json.dump(dict,outfile)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM