因此,我正在尝试记录我正在编写的api返回的json格式,我想知道json结构的文档是否存在任何流行的格式。
请注意,我并不是要测试或验证任何东西,我只是使用它作为文档。还有一些向非常量添加注释的方法(总是返回带有相同值的项目)会很好。
这是我目前不完全考虑的方案:
Plain names refer to identifiers or types.
Some types have type-comment
Strings that appear to be constant(always returned for that type of request) strings are "str"
Constant Numbers would be just the number
Constant null is null
Booleans are true/false for constant booleans or Boolean otherwise
[a,b,c] are lists with 3 items a,b,c
[... ...] is a list of repeating elements of some types/constants/patterns
{a:A,b:B,c:c} and {... ...} is the same for a dictionary.
例:
story := [header,footer]
header := {"data":realHeader,"kind":"Listing"}
realHeader := {"after": null, "before": null, "children": [{"data": realRealHeader, "kind": "t3"}], "modhash": ""}
footer := {"data":AlmostComments,"kind":"Listing"}
AlmostComments := {"data": {"after": null, "before": null, "children": comments, "modhash": ""}, "kind": "t1"}
comments := [...{"data":comment, "kind":"t1"}...]
realRealHeader :=
{"author": string,
"clicked": boolean,
"created": int,
"created_utc": int,
"domain": "code.reddit.com",
"downs": int,
"hidden": boolean,
"id": string-id,
"is_self": boolean,
"levenshtein": null,
"likes": null,
"media": null,
"media_embed": { },
"name": string-id,
"num_comments": int,
"over_18": false,
"permalink": string-urlLinkToStoryStartingFrom/r,
"saved": false,
"score": int,
"selftext": string,
"selftext_html": string-html,
"subreddit": string-subredditname,
"subreddit_id": string-id,
"thumbnail": "",
"title": string,
"ups": int,
"url": "http://code.reddit.com/"
}
comments := {
"author": string,
"body": string-body_html-wout-html,
"body_html": string-html-formated,
"created": int,
"created_utc": int,
"downs": int,
"id": string-id,
"levenshtein": null,
"likes": null,
"link_id": string-id,
"name": string-id",
"parent_id": string-id,
"replies": AlmostComments or null,
"subreddit": string-subredditname,
"subreddit_id": string-id,
"ups": int
}
"mode": "fast" | "medium" | "slow",
,其中每个可能的值都以文字字符串或int或boolean形式明确给出。竖线|
在JSON中(在字符串外部)不合法,因此可以理解其作为元字符的含义。