Method 1:
Read the JSON string in the file,
Then use Json.loads to convert to Python dictionary
Import Jsonstr_file = './960x540/config.json ' with open (Str_file, ' R ') as F: print ("Load str file from {}". Format (str_ file)) str1 = F.read () r = json.loads (str1) print (Type (r)) print (r) print (r[' under_game_score_y '])
Method 2:
Directly with the file cursor F, the JSON string is completed in one step, along with reading and turning into a python dictionary. This is Josn.load (f).
Import Jsonstr_file = './960x540/config.json ' with open (Str_file, ' R ') as F: print ("Load str file from {}". Format (str_ file)) r = json.load (f) Print (type (r)) print (r) print (r[' under_game_score_y ')
Conclusion:
The difference between loads and load in the JSON module is:
Loads is to read the string in the F cursor first, and convert the string into a python dictionary
Load is one step the file cursor f into a python dictionary.
JSON data processing: Reading a JSON string from a file to a Python dictionary