我試圖在結果中顯示帶有重音的陣列,但只顯示沒有重音的陣列。
完成moviedb API:https ://api.themoviedb.org/3/movie/566525 ? api_key = b2f8880475c888056b6207067fbaa197 & language = pt-BR
"genres": [
{
"id": 28,
"name": "A??o"
},
{
"id": 12,
"name": "Aventura"
},
{
"id": 14,
"name": "Fantasia"
}
],
"overview": "Shang-Chi precisa confrontar o passado que pensou ter deixado para trás. Ao mesmo tempo, ele é envolvido em uma teia de mistérios da organiza??o conhecida como Dez Anéis.",
外殼代碼:
getMovieInfo()
{
movieInfo=$(httpGet "https://api.themoviedb.org/3/movie/566525?api_key=b2f8880475c888056b6207067fbaa197&append_to_response=videos&language=pt-BR")
genreOne=$(echo "$movieInfo" | python -c "import sys, json; print json.load(sys.stdin)['genres'][0]['name']" 2> /dev/null )
genreTwo=$(echo "$movieInfo" | python -c "import sys, json; print json.load(sys.stdin)['genres'][1]['name']" 2> /dev/null )
genreThree=$(echo "$movieInfo" | python -c "import sys, json; print json.load(sys.stdin)['genres'][2]['name']" 2> /dev/null )
genres=$(echo "$genreOne $genreTwo $genreThree" | tr " " ",")
overview=$(echo "$movieInfo" | python -c "import sys, json; print json.load(sys.stdin)['overview']" 2> /dev/null )
}
結果:
==========================================
| Title: Shang-Chi and the Legend of the Ten Rings
| Language: en
| Genre: ,Aventura,Fantasia
| Runtime: 132 mins
| Overview:
==========================================
uj5u.com熱心網友回復:
這是在 jq 中執行此操作的更簡潔的方法。此解決方案也可以更好地擴展(您不需要知道陣列中的元素數)
my_function() {
movieInfo="$(httpGet "https://api.themoviedb.org/3/movie/566525?api_key=b2f8880475c888056b6207067fbaa197&append_to_response=videos&language=pt-BR")"
language="$(jq -r '.original_language' <<< $movieInfo)"
genres="$(jq -r '[.genres[].name] | join(",")' <<< $movieInfo)"
runtime="$(jq -r '.runtime' <<< $movieInfo)"
overview="$(jq -r '.overview' <<< $movieInfo)"
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/357967.html
