python 字符串转json
python中字符串怎么转json呢?不知道的小伙伴来看看小编今天的分享吧!
python中字符串怎么转json方法:
python字符串转json对象,需要使用json模块的loads函数
# encoding: utf-8
print "str转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)
输出结果:
str转json
type(string_a): <type 'str'>
dict_a: {u'accessToken': u'521de21161b23988173e6f7f48f9ee96e28', u'User-Agent': u'Apache-HttpClient/4.5.2 (Java/1.8.0_131)'}
type(dict_a): <type 'dict'>
拓展资料:
python中json转字符串。
# encoding: utf-8
print "json转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)
输出结果:
json转str
type(json_b): <type 'dict'>
str_b: {"accessToken": "521de21161b23988173e6f7f48f9ee96e28", "User-Agent": "Apache-HttpClient/4.5.2 (Java/1.8.0_131)"}
type(str_b): <type 'str'>
-
二手昂科雷怎么保养?
二手昂科雷保养:1、机油及机油滤清器的更换主要是针对润滑系统进行的维护保养,润滑系统的主 要作用就是对汽车发动机的各个部件进行有效的润滑,以防过度磨损;2、空气滤芯的作用是在空...
问答查看全文>> -
途观天窗关不上怎么办?
途观天窗关不上的解决方法如下:1、当天窗关不上时,先检查滑轨,很可能缺少润滑,阻力过大时候,天窗会启动自动防夹,表现为关不上;2、天窗主要的保养是滑轨的润滑,如果缺少润滑,时间...
问答查看全文>>
推荐
- 1前置四驱车的优点缺点?383
- 2宝宝手机哪个牌子好 宝宝手机十大品牌排行榜230
- 3礼记经典句子272
- 4需要什么条件才可以做滴滴司机395
- 5电喷发动机启动困难怎么回事422
- 67777777是什么意思 7777777什么梗120
- 7汽车前轮过颠簸路咯噔咯噔响是为什么149
- 82022年稻草人阅读心得体会306