有没有办法用JSON指针选择数组成员的键值?所以对于这个JSON Schema:
"links":[
{
"title": "Create",
"href": "/book",
"method": "POST",
"schema": {}
},
{
"title": "Get",
"href": "/book",
"method": "GET",
"schema": {}
}
]
而不是:
links/0/schema
我希望能够做到:
links/{title=GET}/schema
答案 0 :(得分:0)
显然不是。所以我这样做了:
const links = schema.links;
let ref;
for (const [i, link] of links.entries()) {
if (link.href === req.originalUrl && link.method === req.method) {
ref = `schema.json#/links/${i}/schema`;
break;
}
}
答案 1 :(得分:0)
Json Pointer defined in RFC6901不允许您通过名称选择数组成员。这是RFC中对数组的唯一提及:
If the currently referenced value is a JSON array, the reference token MUST contain either:
* characters comprised of digits ..., or
* exactly the single character "-", making the new referenced
value the (nonexistent) member after the last array element.