【发布时间】:2015-07-29 04:32:21
【问题描述】:
我想从 json 数据文件生成 json 模式,如下所示。(这是使用在线工具生成的,http://jsonschema.net/) 用 JSON.NET 或其他任何方法都可以吗?
Json 数据文件:
{
"graph": [
{
"id": 453,
"cid": 143,
"title": "graph1",
"description": "",
"thumbnailPath": "art.jpg",
"detailPath": "art.jpg",
"link": "www.test.html",
"author": "graph Team"
},
{
"id": 12,
"cid": 121,
"title": "graph2",
"description": "",
"thumbnailPath": "art2.jpg",
"detailPath": "art2.jpg",
"link": "www.test2.html",
"author": "graph Team"
}
]
}
输出:
{
"$schema": "http://json-schema.org/draft-04/schema#",
"id": "/",
"type": "object",
"properties": {
"graph": {
"id": "graph",
"type": "array",
"items": {
"id": "1",
"type": "object",
"properties": {
"id": {
"id": "id",
"type": "integer"
},
"cid": {
"id": "cid",
"type": "integer"
},
"title": {
"id": "title",
"type": "string"
},
"description": {
"id": "description",
"type": "string"
},
"thumbnailPath": {
"id": "thumbnailPath",
"type": "string"
},
"detailPath": {
"id": "detailPath",
"type": "string"
},
"link": {
"id": "link",
"type": "string"
},
"author": {
"id": "author",
"type": "string"
}
}
}
}
}
}
我的目标不是使用工具,因为我想在程序运行时生成它。
【问题讨论】:
-
试试这个工具。它根据查询模式生成一个 json。 github.com/rollrodrig/customjsonbuilder