私はを使用します。それらのJSONデータは大きくネストされており、関連するデータを取得するのには苦労しています。深くネストされたJSON(5つ以上のレイヤー)でデータを取得する方法
データは以下の通りです。私はカテゴリのデータを取得したいと思います。
{
"_embedded": {
"city:search-results": [
{
"_embedded": {
"city:item": {
"_embedded": {
"city:urban_area": {
"_embedded": {
"ua:scores": {
"_links": {
"self": {
"href": "https://api.teleport.org/api/urban_areas/slug:tokyo/scores/"
}
},
"categories": [
{
"color": "#f3c32c",
"name": "Housing",
"score_out_of_10": 5.710999999999999
},
{
"color": "#f3d630",
"name": "Cost of Living",
"score_out_of_10": 3.343
},.....
コードです。私はReact、Redux、Lodashを使い、マップ関数でデータを反復しようとしました。
let item;
if(this.props.data) {
item = _.map(this.props.data._embedded.city:search-results._embedded.city:item._embedded.city:urban_area._embedded.ua:scores.categories,
/** This nested props doesn't work **/
data => {
return (
<div>
<h2>{data.name}</h2>
<p>{data.score_out_of_10}</p>
</div>
)
})
重く入れ子になったJSONデータのデータを反復処理する良い方法はありますか?
ありがとうございました。私はそれについて知らなかった。私はコードを '' {_embedded.city:search-results [0] ._embedded.city:item._embedded.city:urban_area._embedded.ua:scores.categories '、[]) 'city:search-result 'は配列です。その後、それは働いた。ご協力ありがとうございました。 – aaayumi