首页
注册
登录
V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请
登录
推荐学习书目
›
Learn Python the Hard Way
Python Sites
›
PyPI
- Python Package Index
›
http://diveintopython.org/toc/index.html
›
Pocoo
值得关注的项目
›
PyPy
›
Celery
›
Jinja2
›
Read the Docs
›
gevent
›
pyenv
›
virtualenv
›
Stackless Python
›
Beautiful Soup
›
结巴中文分词
›
Green Unicorn
›
Sentry
›
Shovel
›
Pyflakes
›
pytest
Python 编程
›
pep8 Checker
Styles
›
PEP 8
›
Google Python Style Guide
›
Code Style from The Hitchhiker's Guide
V2EX
›
Python
对于提交上来的 json 数据,有无现成的工具来校验每个字段的数据的格式合法性?
leyle
·
2015-07-07 10:08:32 +08:00
· 12573 次点击
这是一个创建于 3723 天前的主题,其中的信息可能已经有所发展或是发生改变。
客户端提交了 json 数据,对于每一个字段,需要确保它的格式的有效性,比如某个字段必须是整数,某个字段必须是字符串,某个字段必须是 YYYY-MM-DD 的日期等,有无现成的工具可用,还是说要自己每一个字段的写正则等代码去校验?
字段
校验
JSON
6 条回复
•
2016-02-07 11:21:13 +08:00
1
lululau
2015-07-07 10:19:05 +08:00
5
http://python-jsonschema.readthedocs.org/en/latest/
2
hiboshi
2015-07-07 10:19:25 +08:00
转为json对象 或数组 遍历 ,单纯采用正则会比较麻烦
3
leyle
OP
2015-07-07 10:36:26 +08:00
@
lululau
多谢。
我自己又造了个轮子,支持传递类型和正则,对每一个字段进行检查,不符合就抛出 http code 是 400 的错误。
你这个功能好多了。我去仔细看看。
4
virusdefender
2015-07-07 11:13:30 +08:00
https://github.com/virusdefender/data_validator
那时候练手用的 没文档 模仿django的form就可以
5
aec4d
2015-07-07 22:17:09 +08:00
https://github.com/formencode/formencode
用的这个 感觉不是很好用-_-
可以自己写规则,当然也内置了很多规则
应该有更好的方案吧
6
guyskk
2016-02-07 11:21:13 +08:00 via Android
楼主可以看看这个
https://github.com/guyskk/validater
关于
·
帮助文档
·
自助推广系统
·
博客
·
API
·
FAQ
·
实用小工具
·
5545 人在线
最高记录 6679
·
Select Language
创意工作者们的社区
World is powered by solitude
VERSION: 3.9.8.5 · 42ms ·
UTC 01:29
·
PVG 09:29
·
LAX 18:29
·
JFK 21:29
Developed with
CodeLauncher
♥ Do have faith in what you're doing.
❯