当前位置: 首页 - 科技 - 知识百科 - 正文

python 字符串转json

来源:懂视网 责编:李赢赢 时间:2021-12-29 17:31:14
文档

python 字符串转json

python中字符串怎么转json方法:python字符串转json对象,需要使用json模块的loads函数#encoding:utf-8print"str转json"import jsonstring_a='{"accessToken"。
推荐度:
导读python中字符串怎么转json方法:python字符串转json对象,需要使用json模块的loads函数#encoding:utf-8print"str转json"import jsonstring_a='{"accessToken"。

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'>

以上就是小编今天的分享了,希望可以帮助到大家。

文档

python 字符串转json

python中字符串怎么转json方法:python字符串转json对象,需要使用json模块的loads函数#encoding:utf-8print"str转json"import jsonstring_a='{"accessToken"。
推荐度:
标签: 字符串 json
  • 热门焦点

最新推荐

猜你喜欢

热门推荐

专题
Top