# 1 JSON string length like dictionary, but not dictionary type, is str type
#例如: User_info is a JSON string, Dict is a dictionary, if the content of the TXT text that identifies dict is a JSON string
User_info = "'
{"name1": "Lily", "name2": "tt", "Name3": "EE"}
‘‘‘
Dict = {"name1": "Lily", "name2": "tt", "Name3": "EE"}
#2, JSON string content such as double quotation marks, cannot use single quotation marks, dictionary single double quotation marks can be
Convert #3, loads strings to dictionaries (loads to single quotes after conversion to dictionaries), dumps dictionaries to strings
#4, www.bejson.com Web site Verify that the string can be converted using JSON
The #5, dumps, and dump methods dumps convert the dictionary to a string, do not write, dump converts the dictionary into a string, writes
# dump () format dump (dictionary, sentence grapple)
#例如
Import JSON
Dict_user = {"name1": "Lily", "name2": "tt", "Name3": "EE"}
With open ("Usertest.txt", "w+", encoding= "Utf-8") as FW:
Json.dump (dict_user,fw,indent=4)
#6, indent indentation in JSON format, generally as dump or dumps method parameter for TXT text JSON format indentation
# to change the txt file suffix to JSON can also implement indentation and color hints
#7, loads (str) converts a string to a dictionary passing a string
# load (handle) converts a string in a file into a dictionary pass a file handle
#例如:
Import JSON
With open ("Users2.txt", "r+", encoding= "Utf-8") as FW:
data = Fw.read ()
Print (data)
User_dict=json.loads (data)
Print (user_dict)
With open ("Users2.txt", "r+", encoding= "Utf-8") as FW:
User_dict2=json.load (FW)
Print (USER_DICT2)
Python--json string related loads dumps load dump