我正在尝试创建一个2D数组,其中将存储播放列表名称和一个Video Items数组。播放列表名称将从一个api调用,而各项将从另一个api调用。我应该从这里继续吗?
const PlayListID = [];
var count = 0;
//Get All the Playlists of the Channel
fetch(`http://192.168.100.5:8086/api/PlayLists`)
.then(res => res.json())
.then(res => {
for (item in res) {
var jsonitem = res[item].playListMasterUrl;
var replval = jsonitem.replace(/"\\/g, "");
var rep = replval.replace(/\\"/g, "");
var obj = JSON.parse(rep);
PlayListID.push(obj);
fetch(`http://192.168.100.5:8086/api/ChannelData/1`)
.then(res => res.json())
.then(res => {
const LivevideoId = []
res.items.forEach(item => {
LivevideoId.push(item)
})
this.setState({
liveVideos: LivevideoId
})
})
.catch(error => {
console.error(error)
})
}
this.setState({
data: PlayListID
})
})
.catch(error => {`
console.error(error)
})
预期的数组应类似于:
[["playlist name",[{item1},{item2},{item3}]],["playlist name",
[{item1},{item2},{item3}]]]
原始数组:
[
{
"playListMasterID": 1,
"playListMasterName": "Chicago Cup 2019 Playlist",
"playListMasterUrl": "{\"kind\":\"youtube#playlist\",\"etag\":\"\\\"8jEFfXBrqiSrcF6Ee7MQuz8XuAM/eWYpzybRPbWtzDWzn6r2nMqpue0\\\"\",\"id\":\"PLWptzt_ZZAV0uCi1VZ_dJvDN2H5fuy982\",\"snippet\":{\"publishedAt\":\"2019-09-02T12:07:58.000Z\",\"channelId\":\"UCjil40e6Lq1vg4qzK0ufEUQ\",\"title\":\"Chicago Cup 2019 Playlist\",\"description\":\"\",\"thumbnails\":{\"default\":{\"url\":\"https://i.ytimg.com/vi/2iI9zOdZEtc/default.jpg\",\"width\":120,\"height\":90},\"medium\":{\"url\":\"https://i.ytimg.com/vi/2iI9zOdZEtc/mqdefault.jpg\",\"width\":320,\"height\":180},\"high\":{\"url\":\"https://i.ytimg.com/vi/2iI9zOdZEtc/hqdefault.jpg\",\"width\":480,\"height\":360},\"standard\":{\"url\":\"https://i.ytimg.com/vi/2iI9zOdZEtc/sddefault.jpg\",\"width\":640,\"height\":480},\"maxres\":{\"url\":\"https://i.ytimg.com/vi/2iI9zOdZEtc/maxresdefault.jpg\",\"width\":1280,\"height\":720}},\"channelTitle\":\"maqtv\",\"localized\":{\"title\":\"Chicago Cup 2019 Playlist\",\"description\":\"\"}},\"contentDetails\":{\"itemCount\":7}}"
}
]
视频Json
[
{
"playListDetailURL": "{\"kind\":\"youtube#playlistItem\",\"etag\":\"\\\"8jEFfXBrqiSrcF6Ee7MQuz8XuAM/4Bk7z7cYWTwJChESSbS1YX3x4-o\\\"\",\"id\":\"UExXcHR6dF9aWkFWMHVDaTFWWl9kSnZETjJINWZ1eTk4Mi45NDk1REZENzhEMzU5MDQz\",\"snippet\":{\"publishedAt\":\"2019-09-04T11:57:15.000Z\",\"channelId\":\"UCjil40e6Lq1vg4qzK0ufEUQ\",\"title\":\"Chicago Cup 2019 Final from Skokie Park, Skokie, IL USA [Recorded]\",\"description\":\"Semi Final & Final \\nSeptember 2nd, 2019 \\nSkokie Park at 3459 Oakton St, Skokie, IL 60076\\n\\n2019 Chicago Cup excitement is mounting among players of the eight teams.\\n\\nThe tournament bowls off in earnest on Saturday at Washington Park in Chicago at 10 am with four matches taking place simultaneously. The official opening will take place at 9 am at the Park with officials meeting the players.\\n\\nPresident of Midwest Cricket Council (MCC) Shiraz Najam says that all is in place for the opening of the ninth edition. “We have worked hard over the past few months to get everything in place for this our marquee tournament. A couple of days ago we finished putting in new Astroturf at the four grounds as we look to up the quality of the cricket.\\n\\n#maq #cricketcouncilusa #t20sports #usopen #usanational #championship #usacricket #ccusa \\n#usopencricket #nationalchampionship #maqt10 \\n#matv #USACRICKET #unitedstates #canada #england \\n#australia #NewZealand #pakistan #germanytourism \\n#switzerland????hongkong???? #India #Bangladesh #Srilanka \\n#southafrica #windies\",\"thumbnails\":{\"default\":{\"url\":\"https://i.ytimg.com/vi/2iI9zOdZEtc/default.jpg\",\"width\":120,\"height\":90},\"medium\":{\"url\":\"https://i.ytimg.com/vi/2iI9zOdZEtc/mqdefault.jpg\",\"width\":320,\"height\":180},\"high\":{\"url\":\"https://i.ytimg.com/vi/2iI9zOdZEtc/hqdefault.jpg\",\"width\":480,\"height\":360},\"standard\":{\"url\":\"https://i.ytimg.com/vi/2iI9zOdZEtc/sddefault.jpg\",\"width\":640,\"height\":480},\"maxres\":{\"url\":\"https://i.ytimg.com/vi/2iI9zOdZEtc/maxresdefault.jpg\",\"width\":1280,\"height\":720}},\"channelTitle\":\"maqtv\",\"playlistId\":\"PLWptzt_ZZAV0uCi1VZ_dJvDN2H5fuy982\",\"position\":0,\"resourceId\":{\"kind\":\"youtube#video\",\"videoId\":\"2iI9zOdZEtc\"}},\"contentDetails\":{\"videoId\":\"2iI9zOdZEtc\",\"videoPublishedAt\":\"2019-09-04T10:32:09.000Z\"}},"
}
]