Home > Article > Backend Development > python string processing
python converts the string into a dictionary
a={"cardtype":"A711","dt":"1447223787","token":"6C7C75327CC6FB4C77051E2BBD85CFAF","appid":"13a876d53ee4da1a","tid":"17bf1867 aa5d4d8e8c0f15a197cb9db5 ","imsi":"460011082618869"}
type(a) --> str
1.
b= eval(a) ; type(b) --> dict
2.
import json
c = josn .loads(a) ;type(c) --> dict
--------------------------------- -------------------------------------------------- ------
Convert the dictionary type to json and output it
import json
v1 = json.load(a)
v2 = json.dumps(v1,sort_keys=True,indent=4)
print v2
-- -The output is as follows:
{
"appid": "13a876d53ee4da1a",
"cardtype": "A711",
"dt": "1447223787",
"imsi": "460011082618869",
"tid": "17bf1867aa5d4d8e8c0f15a197cb9db5" ,
"token": "6C7C75327CC6FB4C77051E2BBD85CFAF"
}