简体   繁体   English

如何获取列表中的特定索引

[英]how to get specific index in list

I have an api and want to integrate in my flutter mobile application.我有一个 api 并想集成到我的 flutter 移动应用程序中。 I want to decode the response, and wanted to access the argument "data".我想解码响应,并想访问参数“数据”。 so the argument "Data" has a list inside.所以参数“数据”里面有一个列表。 I want to store "ABC" in string variable and want to store "123" in separate integer variable.我想将“ABC”存储在字符串变量中,并希望将“123”存储在单独的 integer 变量中。 SO HOW I CAN ACCESS AND STORE THESE 2 DIFFERENT VALUES("ABC" and "123") IN 2 DIFFERENT VARIABLES FROM A LIST , I got stuck with this.那么我如何在列表中的 2 个不同变量中访问和存储这 2 个不同的值(“ABC”和“123”) ,我对此感到困惑。

{
   "data":[
      [
         "ABC",
         123
      ]
   ],
   "success":true
}

You access a dictionary using dict_var["<key>"] .您使用dict_var["<key>"]访问字典。 You can unpack a list using var1, var2 = list_var .您可以使用var1, var2 = list_var解压缩列表。

Code:代码:

theData = {
   "data": [
      [
         "ABC",
         123
      ]
   ],
   "success": True
}
str_data, int_data = theData["data"][0]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM