python 将字符串转换为字典

  在一般的工程处理中,需要将获取的字符串数据转换为字典,这样处理起来会非常方便。

  我获取的是json数据:

content = {"corpus_no":"6470277238193690986","err_msg":"success.","err_no":0,"result":["今天天气怎么样,"],"sn":"27407666631506478813"}

<class 'str'>

JSON到字典转化:
》》》dictinfo = json.loads(content) 输出dict类型

字典到JSON转化:
》》》jsoninfo = json.dumps(dict)输出str类型

原文地址:https://www.cnblogs.com/demo-deng/p/7600408.html