首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >对于颤振中的映射键,是否有"startsWith“方法?

对于颤振中的映射键,是否有"startsWith“方法?
EN

Stack Overflow用户
提问于 2021-05-08 17:13:41
回答 1查看 255关注 0票数 0

我是一个颤振初学者,我被困在把我的API获取的数据转换为我的自定义模型。我使用的API为我提供了以下数据:

代码语言:javascript
复制
{"meals":[{"idMeal":"52852","strMeal":"Tuna Nicoise","strDrinkAlternate":null,"strCategory":"Seafood",
"strArea":"French","strInstructions":"Heat oven to 200C\/fan 180C\/gas 6. Toss the potatoes with 2 tsp oil and some seasoning. Tip onto a large baking tray, then roast for 20 mins, stirring halfway, until crisp, golden and cooked through.\r\nMeanwhile, put eggs in a small pan of water, bring to the boil, then simmer for 8-10 mins, depending on how you like them cooked. Plunge into a bowl of cold water to cool for a few mins. Peel away the shells, then cut into halves.\r\nIn a large salad bowl, whisk together the remaining oil, red wine vinegar, capers and chopped tomatoes. Season, tip in the onion, spinach, tuna and potatoes, then gently toss together. Top with the eggs, then serve straight away.",
"strMealThumb":"https:\/\/www.themealdb.com\/images\/media\/meals\/yypwwq1511304979.jpg","strTags":null,
"strYoutube":"https:\/\/www.youtube.com\/watch?v=3_UAxkx0u6U",
"strIngredient1":"Potatoes","strIngredient2":"Olive Oil","strIngredient3":"Eggs","strIngredient4":"Red Wine Vinegar","strIngredient5":"Capers","strIngredient6":"Sunflower Oil","strIngredient7":"Red Onions","strIngredient8":"Spinach","strIngredient9":"Tuna","strIngredient10":"","strIngredient11":"","strIngredient12":"","strIngredient13":"","strIngredient14":"","strIngredient15":"","strIngredient16":"","strIngredient17":"","strIngredient18":"","strIngredient19":"","strIngredient20":"",
"strMeasure1":"450g","strMeasure2":"2 tblsp ","strMeasure3":"4","strMeasure4":"1 tbls","strMeasure5":"2 tblsp ","strMeasure6":"50g","strMeasure7":"\u00bd","strMeasure8":"100g ","strMeasure9":"400g","strMeasure10":"","strMeasure11":"","strMeasure12":"","strMeasure13":"","strMeasure14":"","strMeasure15":"","strMeasure16":"","strMeasure17":"","strMeasure18":"","strMeasure19":"","strMeasure20":"",
"strSource":"https:\/\/www.bbcgoodfood.com\/recipes\/9529\/winter-tuna-nioise",
"strImageSource":null,"strCreativeCommonsConfirmed":null,"dateModified":null}]}

--我想将以"strIngredient“开头的所有键值存储到列表中,"strMeasure"也是如此

但我还没有找到一种方法可以做到这一点。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-05-08 18:49:00

你可以得到所有的keys,然后根据你的情况检查每一个。

代码语言:javascript
复制
Map<String,String> meals= api_data['meals'][0];

List<String> allKeys = meals.keys.toList();

for(String key in allKeys){
  if(key.startsWith("strIngredient")){
    print(meals[key]);
  }
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/67450205

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档