json转实体类
Project description
jsonModel
json数据转为实体类的工具
python版本
2.7 ~ 3.8
安装
包被上传到pypi
使用pip安装:
$ pip install pyjsonmodel
或 更新包
$ pip install pyjsonmodel --update
使用方法
# 模型
class GModel:
sss = None
class ZModel:
aaa = None
class People:
name = None
age = None
girlFriends = None
zzz = None
# 这里指定属性类型
__doc__ = {
"girlFriends": GModel,
"zzz": ZModel
}
# 引用
import jsonModel
data = '[{"name":"jack","age":13,"girlFriends":[{"sss":"111"},{"sss":"222"}],"zzz":{"aaa":"aaa"}},{"name":"jone","age":21,"girlFriends":[{"sss":"111"},{"sss":"222"}],"zzz":{"aaa":"aaa"}}]'
# json 转 实体类
res = jsonModel.loads(data, People)
# 实体类 转 json
jsonStr = jsonModel.dumps(res)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
pyjsonmodel-1.0.1.tar.gz
(3.7 kB
view hashes)
Built Distribution
Close
Hashes for pyjsonmodel-1.0.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4850854f83492a0a87f847b2e98fcc72c5f77deef34db67ab8f1116c1f1aacc7 |
|
MD5 | 7943a2fbb6f468b2437dc97a69f9ed93 |
|
BLAKE2b-256 | c47d246b85d49378a0e25d412f327607f1efa772a060d8b7ec983c0ffb465fd4 |