XQuery 如何从 JSON 中获取艺术家的姓名
XQuery How can I get the name of the Artist from the JSON
我有以下 JSON 文件
{
"href": "https://api.spotify.com/v1/playlists/37i9dQZF1DX2RxBh64BHjQ/tracks?offset=0&limit=100&additional_types=track",
"items": [
{
"added_at": "2021-11-29T23:29:54Z",
"added_by": {
"external_urls": {
"spotify": "https://open.spotify.com/user/"
},
"href": "https://api.spotify.com/v1/users/",
"id": "",
"type": "user",
"uri": "spotify:user:"
},
"is_local": false,
"primary_color": null,
"track": {
"album": {
"album_type": "single",
"artists": [
{
"external_urls": {
"spotify": "https://open.spotify.com/artist/0Njy6yR9LykNKYg9yE23QN"
},
"href": "https://api.spotify.com/v1/artists/0Njy6yR9LykNKYg9yE23QN",
"id": "0Njy6yR9LykNKYg9yE23QN",
"name": "Nardo Wick",
"type": "artist",
"uri": "spotify:artist:0Njy6yR9LykNKYg9yE23QN"
}
],
"available_markets": [
"AD",
"AE",
"AG",
"AL",
"AM",
],
"external_urls": {
"spotify": "https://open.spotify.com/album/6SEeNB2xGW1kmysKSvWYqC"
},
"href": "https://api.spotify.com/v1/albums/6SEeNB2xGW1kmysKSvWYqC",
"id": "6SEeNB2xGW1kmysKSvWYqC",
],
"name": "Me or Sum (feat. Future & Lil Baby)",
}
我想使用 Xquery 获取艺术家的名字,它是“Nardo Wick”,但出了点问题。
这是我的代码:
xquery version "3.1";
let $hou := fn:json-doc("spoti.json")?artists?*
return
<Playlist>
<song>
{
for $item in fn:distinct-values($hou?name)
return <name>{$item}</name>
}
</song>
</Playlist>
所以,我的问题是,如何从 JSON 或“艺术家”中的任何其他内容中获取艺术家的名字。
您的 JSON 片段不完整,但一些更现实的 selection(试图 select 进入呈现的 JSON)将是 ?items?1?track?album?artists?1?name
. (未测试)
您可以考虑使用
let $hou := (fn:json-doc("spoti.json") => map:find("artists"))?*
虽然这有点脆弱,因为它假定键“艺术家”不会出现在其他任何地方。
我有以下 JSON 文件
{
"href": "https://api.spotify.com/v1/playlists/37i9dQZF1DX2RxBh64BHjQ/tracks?offset=0&limit=100&additional_types=track",
"items": [
{
"added_at": "2021-11-29T23:29:54Z",
"added_by": {
"external_urls": {
"spotify": "https://open.spotify.com/user/"
},
"href": "https://api.spotify.com/v1/users/",
"id": "",
"type": "user",
"uri": "spotify:user:"
},
"is_local": false,
"primary_color": null,
"track": {
"album": {
"album_type": "single",
"artists": [
{
"external_urls": {
"spotify": "https://open.spotify.com/artist/0Njy6yR9LykNKYg9yE23QN"
},
"href": "https://api.spotify.com/v1/artists/0Njy6yR9LykNKYg9yE23QN",
"id": "0Njy6yR9LykNKYg9yE23QN",
"name": "Nardo Wick",
"type": "artist",
"uri": "spotify:artist:0Njy6yR9LykNKYg9yE23QN"
}
],
"available_markets": [
"AD",
"AE",
"AG",
"AL",
"AM",
],
"external_urls": {
"spotify": "https://open.spotify.com/album/6SEeNB2xGW1kmysKSvWYqC"
},
"href": "https://api.spotify.com/v1/albums/6SEeNB2xGW1kmysKSvWYqC",
"id": "6SEeNB2xGW1kmysKSvWYqC",
],
"name": "Me or Sum (feat. Future & Lil Baby)",
}
我想使用 Xquery 获取艺术家的名字,它是“Nardo Wick”,但出了点问题。 这是我的代码:
xquery version "3.1";
let $hou := fn:json-doc("spoti.json")?artists?*
return
<Playlist>
<song>
{
for $item in fn:distinct-values($hou?name)
return <name>{$item}</name>
}
</song>
</Playlist>
所以,我的问题是,如何从 JSON 或“艺术家”中的任何其他内容中获取艺术家的名字。
您的 JSON 片段不完整,但一些更现实的 selection(试图 select 进入呈现的 JSON)将是 ?items?1?track?album?artists?1?name
. (未测试)
您可以考虑使用
let $hou := (fn:json-doc("spoti.json") => map:find("artists"))?*
虽然这有点脆弱,因为它假定键“艺术家”不会出现在其他任何地方。