python string processing

巴扎黑
Release: 2016-11-26 11:33:33
Original
1037 people have browsed it

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"
}

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!