当前位置: 首页 > news >正文

html5网站后台管理系统百度网盘资源搜索

html5网站后台管理系统,百度网盘资源搜索,jsp开源网站,个人网页设计版面json 官方文档:http://docs.python.org/library/json.html Json在线解析网站:http://www.json.cn/# JSON(JavaScript Object Notation) 是一种轻量级的数据交换格式,它使得人们很容易的进行阅读和编写。同时也方便了机器进行解析和生成。适…

json

官方文档:http://docs.python.org/library/json.html

Json在线解析网站:http://www.json.cn/#

JSON(JavaScript Object Notation) 是一种轻量级的数据交换格式,它使得人们很容易的进行阅读和编写。同时也方便了机器进行解析和生成。适用于进行数据交互的场景,比如网站前台与后台之间的数据交互。

1.1、json.loads()

把Json格式字符串解码转换成Python对象,从json到python的类型转化对照如下:

JSONPython
objectdict
arraylist
stringstr
number (int)int
number (real)float
trueTrue
falseFalse
nullNone
import jsonstrList = '[1, 2, 3, 4]'
strDict = '{"city": "北京", "name": "大猫"}'print(json.loads(strList))
print(json.loads(strDict))
'''
输出结果:
[1, 2, 3, 4]
{"city": "北京", "name": "大猫"}
'''

1.2、json.dumps()

实现python类型转化为json字符串,返回一个str对象把一个Python对象编码转换成Json字符串,从python原始类型向json类型的转化对照如下:

PythonJSON
dictobject
list, tuplearray
strstring
int, float, int- & float-derived Enumsnumber
Truetrue
Falsefalse
Nonenull
import jsonlistStr = [1, 2, 3, 4]
tupleStr = (1, 2, 3, 4)
dictStr = {"city": "北京", "name": "大猫"}print(json.dumps(listStr))
print(json.dumps(tupleStr))# 注意:json.dumps() 序列化时默认使用的ascii编码
# 添加参数 ensure_ascii=False 禁用ascii编码,按utf-8编码
print(json.dumps(dictStr))
print(json.dumps(dictStr, ensure_ascii=False))'''
输出结果:
[1, 2, 3, 4]
[1, 2, 3, 4]
{"city": "\u5317\u4eac", "name": "\u5927\u732b"}
{"city": "北京", "name": "大猫"}
'''

1.3、json.load()

读取文件中json形式的字符串元素 转化成python类型

import jsonstrList = json.load(open("listStr.json"))
print(strList)strDict = json.load(open("dictStr.json"))
print(strDict)

1.4、json.dump()

将Python内置类型序列化为json对象后写入文件

import jsonlistStr = [{"city": "北京"}, {"name": "大刘"}]
json.dump(listStr, open("listStr.json","w"), ensure_ascii=False)dictStr = {"city": "北京", "name": "大刘"}
json.dump(dictStr, open("dictStr.json","w"), ensure_ascii=False)

JsonPath

**官方文档:**http://goessner.net/articles/JsonPath
https://pypi.org/project/jsonpath/

JsonPath用符号$表示最外层对象,类似于Xpath中的根元素

JsonPath可以通过点语法来检索数据,如:shell $.store.book[0].title,也可以使用中括号[]的形式,如shell $['store']['book'][0]['title']

2.1、JsonPath与Xpath语法对比

Json结构清晰,可读性高,复杂度低,非常容易匹配,下表中对应了XPath的用法

XPathJSONPath描述
/$根节点
.@现行节点v
/.or[]取子节点
n/a取父节点,Jsonpath未支持
//就是不管位置,选择所有符合条件的条件
**匹配所有元素节点
@n/a根据属性访问,Json不支持,因为Json是个Key-value递归结构,不需要。
[][]迭代器标示(可以在里边做简单的迭代操作,如数组下标,根据内容选值等)
[,]支持迭代器中做多选。
[]?()支持过滤操作.
n/a()支持表达式计算
()n/a分组,JsonPath不支持
import jsonpathjsonobj ={"state":1,"message":"success","content":{"data":{"allCitySearchLabels":{"A":[{"id":105795,"name":"澳门特别行政区"},{"id":671,"name":"安庆"},{"id":601,"name":"鞍山"}]}}}
}
# 从根节点开始,匹配name节点
citylist = jsonpath.jsonpath(jsonobj,'$..name')

jsonpath-rw

官方文档:https://pypi.python.org/pypi/jsonpath-rw
https://github.com/kennknowles/python-jsonpath-rw

安装

pip install jsonpath-rw

用法

>>> from jsonpath_rw import jsonpath, parse
>>> json_obj = {"student":[{"male":176,"female":162},{"male":174,"female":159}]}
>>> jsonpath_expr = parse("student[*].male")
>>> male = jsonpath_expr.find(json_obj)
>>> male #返回的是list,但是不是我们想要的值
[DatumInContext(value=176, path=Fields('male'), context=DatumInContext(value={'male': 176, 'female': 162}, path=<jsonpath_rw.jsonpath.Index object at 0x000001C6B95109B0>, context=DatumInContext(value=[{'male': 176, 'female': 162}, {'male': 174, 'female': 159}], path=Fields('student'), context=DatumInContext(value={'student': [{'male': 176, 'female': 162}, {'male': 174, 'female': 159}]}, path=This(), context=None)))), DatumInContext(value=174, path=Fields('male'), context=DatumInContext(value={'male': 174, 'female': 159}, path=<jsonpath_rw.jsonpath.Index object at 0x000001C6B9510588>, context=DatumInContext(value=[{'male': 176, 'female': 162}, {'male': 174, 'female': 159}], path=Fields('student'), context=DatumInContext(value={'student': [{'male': 176, 'female': 162}, {'male': 174, 'female': 159}]}, path=This(), context=None))))]#想要获取值,要用如下方法
>>> [match.value for match in male]
[176, 174]------------------------------------------------------------------------------------
>>> jsonpath_expr = parse('foo[*].baz')
>>> from jsonpath_rw.jsonpath import Fields
>>> from jsonpath_rw.jsonpath import Slice
#jsonpath_expr_direct 等价于jsonpath_expr 
>>> jsonpath_expr_direct = Fields('foo').child(Slice('*')).child(Fields('baz'))>>> [match.value for match in jsonpath_expr.find({'foo': [{'baz': 1}, {'baz': 2}]})]
[1, 2]>>> [str(match.full_path) for match in jsonpath_expr.find({'foo': [{'baz': 1}, {'baz': 2}]})]
['foo.[0].baz', 'foo.[1].baz']>>> [match.value for match in parse('a.*.b.`parent`.c').find({'a': {'x': {'b': 1, 'c': 'number one'}, 'y': {'b': 2, 'c': 'number two'}}})]
['number two', 'number one']

PS:这里再为大家推荐几款比较实用的json在线工具供大家参考使用:

在线JSON代码检验、检验、美化、格式化工具: http://tools.jb51.net/code/json

JSON在线格式化工具: http://tools.jb51.net/code/jsonformat

在线XML/JSON互相转换工具: http://tools.jb51.net/code/xmljson

json代码在线格式化/美化/压缩/编辑/转换工具: http://tools.jb51.net/code/jsoncodeformat

在线json压缩/转义工具:
http://tools.jb51.net/code/json_yasuo_trans

参考:https://www.cnblogs.com/wongbingming/p/6896886.html
https://blog.csdn.net/Ka_Ka314/article/details/81014589
https://www.jianshu.com/p/9721ddb9546e
https://www.jb51.net/article/144815.htm

http://www.zhongyajixie.com/news/12199.html

相关文章:

  • idea可以做网站吗百度入驻绍兴
  • 网站备案证明培训机构
  • 一站式网站建设行业百度快速收录开通
  • 深圳建站公司品牌网站建设自媒体
  • 丹东市网站开发公司西安百度快速排名提升
  • 购买商标百度seo发帖推广
  • 中山市建设安全监督站网站游戏app拉新平台
  • 长春疫情最新消息今天又封了seo网站排名查询
  • 如何对自己做的php网站加密安徽网站设计
  • 荆州做网站的公司苏州首页排名关键词优化
  • 做机票在线预订网站构建新发展格局
  • 怎么用模板做网站客服外包
  • 行业网站建设申请报告域名批量查询系统
  • 沧州网站建设 3tseoseo软件推广哪个好
  • 苏州建网站网络推广与网络营销的区别
  • 东莞网站开发推荐如何搜索关键词热度
  • wordpress主页加关键词厦门百度整站优化服务
  • 上海做网站公司哪家好优化大师官网下载
  • 客户评价 网站建设大庆网络推广
  • 江苏有哪些做网站建设的公司网络推广团队
  • 濮阳网站建设熊掌网络seo zac
  • 受欢迎的佛山网站制作百度云搜索引擎官网
  • 为加强政府网站建设电子商务营销的概念
  • 潍坊专业网站建设怎么收费郑州学校网站建设
  • 优秀建筑模型案例作品沈阳专业网站seo推广
  • 为什么wordpress 打开很慢外包seo服务口碑好
  • 武义住房和城乡建设局网站外贸高端网站设计公司
  • wordpress 获取titleseo接单一个月能赚多少钱
  • 企业如何宣传推广seo关键词搜索和优化
  • 如何创建电子商务网站搜索引擎优化的定义