python 字符串处理

阅读更多
python 把字符串 转换成 字典
a={"cardtype":"A711","dt":"1447223787","token":"6C7C75327CC6FB4C77051E2BBD85CFAF","appid":"13a876d53ee4da1a","tid":"17bf1867aa5d4d8e8c0f15a197cb9db5","imsi":"460011082618869"}
type(a) --> str
1.
b= eval(a) ; type(b) --> dict
2.
import json
c = josn.loads(a)  ;type(c) --> dict

-----------------------------------------------------------------------------------------
把字典类型转换成 json 形式输出
import json
v1 = json.load(a)
v2 = json.dumps(v1,sort_keys=True,indent=4)
print v2
---输出如下:
{
    "appid": "13a876d53ee4da1a",
    "cardtype": "A711",
    "dt": "1447223787",
    "imsi": "460011082618869",
    "tid": "17bf1867aa5d4d8e8c0f15a197cb9db5",
    "token": "6C7C75327CC6FB4C77051E2BBD85CFAF"
}

你可能感兴趣的:(python)