首页 > 其他分享 >json 包 转字符串为dict json.loads(data_str)

json 包 转字符串为dict json.loads(data_str)

时间:2023-07-25 12:13:44浏览次数:34  
标签:json dict str print John data

import json

# # 假设有一个 JSON 对象
# data = {
#     "name": "John",
#     "age": 30,
#     "city": "New York"
# }
#
# # 将 JSON 对象转换为字符串
# json_str = json.dumps(data)
#
# print(json_str)
# str 转json 类型是字典
data_str= '{"name": "John", "age": 30, "city": "New York"}'
data_json=json.loads(data_str)
print(type(data_json)) #<class 'dict'>
print(data_json['name']) # 从字典中获取dict[key]=value  John

 

标签:json,dict,str,print,John,data
From: https://www.cnblogs.com/haha1988/p/17579546.html

相关文章

  • 论文阅读笔记:Quasi-Newton solver for robust non-rigid registration
    论文题目:Quasi-Newtonsolverforrobustnon-rigidregistration,为CVPR2020论文,并提供了开源代码,详见Fast_RNRR0.概述本论文提出了一种非刚性配准方法。......
  • 大json传输优化方法
    1.http流式传输数据压缩gzip、deflate、br分块传输Transfer-Encoding:chunked范围请求Range:bytes=0-100多段数据multipart/byteranges分隔标记boundary类似于文件上传下载2.json特有压缩算法     参考:基于HTTP流式传输的长时响应体验提升    ......
  • 模型类中建立外键的常用方法 db_constraint=False,self.user.id
    1.user=models.ForeignKey(to=User,related_name='order_user',on_delete=models.DO_NOTHING,db_constraint=False,verbose_name="下单用户") to=Order:这是ForeignKey的一个参数,用于指定这个外键字段将关联到的目标模型。在这个例子中,外键字段将关联到名为Order的模......
  • Python - String Methodology
    >>>dir("")['__add__','__class__','__contains__','__delattr__','__dir__','__doc__','__eq__','__format__','__ge__','__getattribute__&......
  • GDAL-Python将s57数据转换为GeoJSON
    fromosgeoimportogrimportsubprocessimportglobimportosOGR_S57_OPTIONS="SPLIT_MULTIPOINT=ON,ADD_SOUNDG_DEPTH=ON"defGetAllS57Repertory():S57Path=[]for_fileinglob.glob(('{0}{1}*.000').format(path,os.sep)):......
  • 字符格式化-逐步总结-f-string
    Python3.6引入了一个新的格式化字符串的方法:f-string(formattedstring),它可以直接把变量写在字符串中,使得格式化的字符串看起来很直观。f可以小写,也可以用大写F。一、变量使用:例1:name='张三'print(f'姓名:{name}')>>>姓名:张三。简单说就是{}里直接加变量。例2:i=0print......
  • python jsonpickle模块不序列化私有变量
    jsonpickle模块可以把对象序列化为JSON文件,还是比较方便的.但是并不是所有变量都需要序列化的,比如有些私有变量就不需要序列化,下面是实现方法:importjsonpickleclassNoSerailPrivates:'''表示不序列化私有变量,以_开头都变量'''def__getstate__(self):......
  • Code-OpenSource-JSON for Modern C++ v3.10.5
    Code-OpenSource-JSONforModernC++v3.10.5github.com/nlohmann/jsonhttps://json.nlohmann.me/home/exceptions/#version-historyhttps://json.nlohmann.me/api/macros/json_diagnostics/#extended-diagnostic-messages#defineJSON_DIAGNOSTICS1输出详细信息......
  • 前端请求报错:'JSON parse error: syntax error, expect {, actual e…1, line 1, colu
    1、如果不用JSON.stringify(inputJson)包起来就会报错letinputJson={"selectUid":selectUid};varresponse=await$.ajax({type:'POST',url:'xxx',data:inputJson,//正确的是JSON.stringify(inputJson)......
  • 为什么总是说“无法将类型"string"转换为"char"”
    https://bbs.csdn.net/topics/100053438stringidtext=formID.id;string[]idarry=idtext.Split(",");说明:formID.id是从form2传过来的,现在在form1对传来字符串进行分割处理,却总是提示“无法将类型"string"转换为"char"”? 原因:应该用单引号string[]idarry=idtext.Split(......