[英]How to get element in 2d Java ArrayList?
I have converted a json string into a java arraylist and I'm looking to access a specific element.我已经将一个 json 字符串转换为一个 java arraylist,我正在寻找访问一个特定的元素。
.get(0).get(2) for example doesn't work as I found on another question. .get(0).get(2) 例如不起作用,因为我在另一个问题上发现。
When I use .get(0) I get the following reposnse:当我使用 .get(0) 时,我得到以下回复:
[{ID=d224fe6b2d35728bbb9c9132db015ba0, Name=dl, DisplayName=Sneakers, MatchTypes=[object], Score=1.0, PassParams=reqID=MjAxOC0wMy0wMSAxNTowNTo0MS40NTcwNzM4MTMgKzAwMDAgVVRDIG09Kzc2MzIwNi45ODYzODkxNDZfXzA0MTgyMWEyNDg5MjZhNTZiLTYwYjBjNzA0ZDQ0NF9KaWtLTQ==} [{ID = d224fe6b2d35728bbb9c9132db015ba0,名称= dl时,显示名称=运动鞋,MatchTypes = [对象],分数= 1.0,PassParams = REQID = MjAxOC0wMy0wMSAxNTowNTo0MS40NTcwNzM4MTMgKzAwMDAgVVRDIG09Kzc2MzIwNi45ODYzODkxNDZfXzA0MTgyMWEyNDg5MjZhNTZiLTYwYjBjNzA0ZDQ0NF9KaWtLTQ ==}
So it looks like the arraylist is a list of lists.所以看起来 arraylist 是一个列表列表。
I'm looking to access the DisplayName value我正在寻找访问 DisplayName 值
The only code I have has been to convert the json string and the attempt at accesing arraylist:我唯一的代码是转换 json 字符串并尝试访问 arraylist:
public void setJson(String jsonString) {
Gson googleJson = new Gson();
ArrayList array = googleJson.fromJson(jsonString, ArrayList.class);
String keyword = array.get(0).get(2).toString();
}
Any help is much appreciated!任何帮助深表感谢!
nested for loops to exhausted search is the easiest way for beginners;嵌套 for 循环到穷尽搜索是初学者最简单的方法; for example例如
for (int I = 0; I < array.length; I++)
{
for (int j = 0; j < array.length; j++)
{
}
}
then do an if else statement to return the statement you want;然后执行 if else 语句以返回您想要的语句; and give you the location.并给你位置。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.