I try to extract some extra information if my query returns a result.
如果我的查询返回一个结果,我尝试提取一些额外的信息。
For example in this query, notable_for returns as "/music/musical_group" and I want to merge another query to extract some information about "/music/musical_group" like its "name"
例如,在这个查询中,notable_for返回为“/music/musical_group”,我想合并另一个查询来提取关于“/music/musical_group”的一些信息,比如它的“名称”
[{
"id": "/en/pearl_jam",
"mid":None,
"/common/topic/notable_for": [],
"name":[]
}]
But if it does not return anything I dont want my query fails. For example, for the query below it returns a null list for the field "notable_for"
但是如果它不返回任何东西,我就不希望我的查询失败。例如,对于下面的查询,它为字段“notable_for”返回一个空列表
[{
"id": "/music/musical_group",
"mid":None,
"/common/topic/notable_for": [],
"name":[]
}]
How should I envelope my queries for such purpose?
我该如何将我的查询封装起来?
2 个解决方案
#1
2
You chose a pseudoproperty (*/common/topic/notable_for*) rather than a real property as your example and it behaves a little bit differently. For a real property, you can use @masouras's shorthand notation ([{}]) if you want to get all subproperties, but if you wanted to pick, say, one or two, the trick is to use the "optional" keyword.
您选择了一个pseudoproperty (*/common/topic/notable_for*),而不是一个实际的属性作为示例,它的行为稍有不同。对于一个真正的属性,如果想要获得所有子属性,可以使用@masouras的简化符号([{}]),但是如果您想要选择,比方说,一两个,诀窍是使用“可选”关键字。
For example, this query:
例如,这个查询:
[{
"id": "/m/01mntvx",
"type":"/music/musical_group",
"/music/musical_group/member": [{
"member": {
"name": null
},
"optional": true
}],
"name":null
}]
will work even if a the band had no members listed.
即使乐队没有成员名单也能工作。
#2
0
Is this what you are asking:
这就是你要问的:
[{ "id": "/en/pearl_jam", "mid": null, "/common/topic/notable_for": [{}], }]
[{ " id ":" / en / pearl_jam”、“中期”:null," /共同/主题/ notable_for”:({ })})
http://tinyurl.com/7tchree
#1
2
You chose a pseudoproperty (*/common/topic/notable_for*) rather than a real property as your example and it behaves a little bit differently. For a real property, you can use @masouras's shorthand notation ([{}]) if you want to get all subproperties, but if you wanted to pick, say, one or two, the trick is to use the "optional" keyword.
您选择了一个pseudoproperty (*/common/topic/notable_for*),而不是一个实际的属性作为示例,它的行为稍有不同。对于一个真正的属性,如果想要获得所有子属性,可以使用@masouras的简化符号([{}]),但是如果您想要选择,比方说,一两个,诀窍是使用“可选”关键字。
For example, this query:
例如,这个查询:
[{
"id": "/m/01mntvx",
"type":"/music/musical_group",
"/music/musical_group/member": [{
"member": {
"name": null
},
"optional": true
}],
"name":null
}]
will work even if a the band had no members listed.
即使乐队没有成员名单也能工作。
#2
0
Is this what you are asking:
这就是你要问的:
[{ "id": "/en/pearl_jam", "mid": null, "/common/topic/notable_for": [{}], }]
[{ " id ":" / en / pearl_jam”、“中期”:null," /共同/主题/ notable_for”:({ })})
http://tinyurl.com/7tchree