Home > other >  Python3, string turn to a dictionary type failure, cannot be used
Python3, string turn to a dictionary type failure, cannot be used

Time:04-04

The great god, and the development of today when encounter a problem, always not solve, is about python3, string turn to a dictionary type of failure,
I declare a string variable b, but I no matter use what method can convert it into a dictionary type
 
B="{' d ':' none ', 'in the' : 'none', 'wa' : 'none', 'playpaws' :' play888 '}"
# dlist=json. Loads (b) results: print (type (dlist)) & lt; The class 'STR' & gt;
# dlist=eval (b) results: print (type (dlist)) & lt; The class 'STR' & gt;

Screenshots are as follows:

CodePudding user response:

Personally, python and json on the definition and use of single and double quotes are different,

Try the following code:
 import json 
B='{" d ":" none ", "in" : "none", "wa" : "none", "playpaws" : "play888"}'
Dlist=json. Loads (b)
Print (dlist)
Print (dlist [' wa '])