我有字串資料串列,例如:
[
https://example.com/app/audio/14/5/1.mp3,
https://example.com/app/audio/14/5/2.mp3,
https://example.com/app/audio/14/5/3.mp3,
https://example.com/app/audio/14/5/4.mp3,
https://example.com/app/audio/14/5/5.mp3,
https://example.com/app/audio/14/5/6.mp3,
https://example.com/app/audio/14/5/7.mp3,
https://example.com/app/audio/14/5/8.mp3,
https://example.com/app/audio/14/5/9.mp3,
https://example.com/app/audio/14/5/10.mp3,
https://example.com/app/audio/14/5/11.mp3,
https://example.com/app/audio/14/5/12.mp3,
https://example.com/app/audio/14/5/13.mp3,
https://example.com/app/audio/14/5/14.mp3,
https://example.com/app/audio/14/5/15.mp3
]
我正在尋找從這個串列中獲取特定字串的解決方案。例如,如果要獲取 number 5,它應該回傳https://example.com/app/audio/14/5/5.mp3字串。
我知道你可能會說它從
0第 5 個字串 開始,但我正在尋找那個特定的名稱而不是行索引https://example.com/app/audio/14/5/6.mp3。https://example.com/app/audio/14/5/5.mp3
Code
這是我到目前為止所擁有的:
// Load file
String file = currentLang == "id" ? "assets/lists/a-player-id.json" :
currentLang == "fa" ? "assets/lists/a-player-fa.json" :
"assets/lists/a-player-en.json";
String data = await DefaultAssetBundle.of(context).loadString(file);
var jsonResult = jsonDecode(data);
// Get data from loaded file
var playlist;
var audios;
for(var i = 0; i < jsonResult.length; i ) {
if(jsonResult[i]['name'] == bookName || jsonResult[i]['name_en'] == bookName || jsonResult[i]['name_fa'] == bookName){
playlist = jsonResult[i]['playList'];
audios = jsonResult[i]['audios']; // sample data is presented at the top of question.
}
}
// Get specific string from "audios list"
var myStaticNumber = 5;
// Here I need help to get myStaticNumber from audios list.
有什么建議嗎?
uj5u.com熱心網友回復:
您可能正在尋找這個:
StringList[myStaticNumber-1];
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/497263.html
