JSON format is small and small, suitable for configuration files, especially in large projects, you can classify the configuration information into different JSON files, and then read the configuration file in the configuration file data to be assigned, here in Python as an example to illustrate:
Suppose you save the following information in the Yourfile.json file:
{ "User_message":{ "name":"Lowman", " Age":" -", }, "Database":{ "USER":"Root", "Passwor":"123", }}
To use JSON in Python, you need to reference JSON:
Try : Import JSON except importerror: import Simplejson as JSON
This reference uses the try except to refer to JSON from Simplejson if the reference JSON fails. The former performs better, but some systems may not have this package installed.
With open ("The path of your JSON File/yourfile.json", "R") as Jsonfile: = jsonfile.read () = JSO N.loads (Val) # It should also be possible to use the Eval () function, Messageconfig = eval (val)
The above code first opens the file with open, then reads the contents into the Val variable, and then uses the json.loads(val)
method to convert the string to a Python Dictionary object so that it can be used in the program, using the following method (need to get data based on the actual JSON file data structure area)
Mes_config = messageconfig["user_message"= mes_config["name"]
Age = mes_config["Age"]
It projects use JSON format data to save project configuration information, and then read the contents of the JSON file in the configuration file to assign values