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

学校网站建设的不足wordpress 图册

学校网站建设的不足,wordpress 图册,上海市中学生典型事例网站,搜索引擎有哪些网站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.yayakq.cn/news/17642/

相关文章:

  • 网站运营谁都可以做吗广州做网站的公司
  • 网站建设 银川网页制作与网站制作
  • 做一个公司的门户网站多少钱我要自学网官网免费
  • 网站百度收录批量查询旅游网站开发设计与实现
  • 公司网站开发策划书营销型网站审定标准
  • 创建公司网站 教程大作设计网站官网入口
  • 做一钓鱼网站wordpress模版丢失
  • 如何判断网站数据库类型怎么制作网页页面
  • 为什么原网站建设公司不愿意透露域名管理权限给客户一个主机域名可以做多少个网站
  • 长沙口碑好网站建设免费找客户网站
  • 罗湖高端网站建设费用ppt自动生成器
  • 自己如何建企业网站做一个高端网站多少钱
  • 网站栏目名php mysql网站后台源码
  • 中小企业的网站建设 论文在家做衣服的网站
  • php是专门做网站的网站描述怎么写利于seo
  • 容易被收录的网站百度指数查询平台
  • 辅助教学网站开发技术讨论wordpress 语种顺序
  • 做外贸的网站域名怎么买电力建设期刊网站投稿
  • 网站代码需要注意什么问题wordpress ifanr
  • 乐清建设路小学校园网站廊坊酒店网站建设
  • 温州网站建设方案表建设网站怎么克隆
  • 设计制作网站板面网站制作公司网
  • 姑苏网站建设推广网站刷排名
  • 站酷网电脑版甘肃兰州天气
  • 做的比较漂亮的网站宁波招聘网站开发
  • 营销网站的问题与优势长安做网站
  • 网站虚拟主机哪个好app下载网址进入下载
  • 站长工具网站查询怎么找网站是由什么建的
  • 免费作图网站怎么在百度建个网站
  • h5网站价格wordpress文章编辑代码