我想知道遍历此ArrayList的最佳方法,此ArrayList来自来自API的响应,这是该ArrayList: 迭代ArrayList的
的问题是,我不知道如何让“ ID”和‘价值’从环, 我知道ArrayList的大小,但我没有任何想法如何打印‘从这个阵列
for(int i=1; i <= contacts.size(); i++) {
//Example System.out.print(contacts[i]->id);
//Example System.out.print(contacts[i]->contact_name) ;
//Example System.out.print(contacts[i]->numbers);
//Example System.out.print(contacts[i]->emails);
//I want to print id and value
//
}
在onResponse我把这种温控功能键’和‘值’例如:
ServerResponse resp = response.body();
functionExample((ArrayList) resp.getResponse());
functionExample有一个ArrayList作为参数。 这是从我的resp.getResponse我的结果():
这是我的JSON从API:
{
"result": "success",
"message": "Lista de Contactos",
"response": [
{
"id": 1,
"contact_name": "EDIFICADORA JUANA",
"numbers": "{24602254,55655545}",
"emails": "{[email protected],[email protected]}"
},
{
"id": 2,
"contact_name": "LA MEJOR",
"numbers": "{25445877,25845877}",
"emails": "{[email protected]}"
}
]
}
我感谢所有帮助。
哪里是你的JSON? – AbhayBohra
研究使用'JSONObject'和'JSONArray'。这些是您将用于Android的最基本的工具。 –