我有字符串数据列表,如:
[
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
]
我正在寻找从这个列表中获取特定字符串的解决方案。例如,如果要获取编号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.
有什么建议吗
您正在寻找以下内容:
StringList[myStaticNumber-1];