...">
瀏覽量:143次
python中字符串怎么轉(zhuǎn)json呢?不知道的小伙伴來看看陽泰小編今天的分享吧!
python中字符串怎么轉(zhuǎn)json方法:
python字符串轉(zhuǎn)json對象,需要使用json模塊的loads函數(shù)
# encoding: utf-8
print "str轉(zhuǎn)json"
import json
string_a = '{"accessToken": "521de21161b23988173e6f7f48f9ee96e28", "User-Agent": "Apache-HttpClient/4.5.2 (Java/1.8.0_131)"}'
print "type(string_a): ", type(string_a)
dict_a = json.loads(string_a)? # json_str == dict
print "dict_a: ", dict_a
print "type(dict_a): ", type(dict_a)
輸出結(jié)果:
str轉(zhuǎn)json
type(string_a):?
dict_a:? {u'accessToken': u'521de21161b23988173e6f7f48f9ee96e28', u'User-Agent': u'Apache-HttpClient/4.5.2 (Java/1.8.0_131)'}
type(dict_a):?
拓展資料:
python中json轉(zhuǎn)字符串。
# encoding: utf-8
print "json轉(zhuǎn)str"
import json
json_b = {"accessToken": "521de21161b23988173e6f7f48f9ee96e28", "User-Agent": "Apache-HttpClient/4.5.2 (Java/1.8.0_131)"}
print "type(json_b): ", type(json_b)
str_b = json.dumps(json_b)
print "str_b: ", str_b
print "type(str_b): ", type(str_b)
輸出結(jié)果:
json轉(zhuǎn)str
type(json_b):?
str_b:? {"accessToken": "521de21161b23988173e6f7f48f9ee96e28", "User-Agent": "Apache-HttpClient/4.5.2 (Java/1.8.0_131)"}
type(str_b):?
[聲明]本網(wǎng)轉(zhuǎn)載網(wǎng)絡媒體稿件是為了傳播更多的信息,此類稿件不代表本網(wǎng)觀點,本網(wǎng)不承擔此類稿件侵權(quán)行為的連帶責任。故此,如果您發(fā)現(xiàn)本網(wǎng)站的內(nèi)容侵犯了您的版權(quán),請您的相關(guān)內(nèi)容發(fā)至此郵箱【779898168@qq.com】,我們在確認后,會立即刪除,保證您的版權(quán)。
官網(wǎng)優(yōu)化
整站優(yōu)化
渠道代理
400-655-5776