2015-04-24 63 views
1

我是新玩框架。在播放框架中迭代对象列表

我写了这个Java代码来获取用户

List<Person> personsDetails = new Model.Finder(String.class, Person.class).all(); 

的细节这是我的JSON字符串

[{"id":"1","email":"[email protected]","password":"zxcv","login_method":"2"}, 
{"id":"2","email":"[email protected]","password":"abcdef","login_method":"3"}] 

如何通过ID获取特定的用户?

回答

2

方法1: 您需要遍历列表personsDetails,并检查特定的ID,你想每次通过ID获取特定的人。


方法2: 你可以准备ID的Map和Person - >Map<Integer, Person>。并使用map.get(Object key)方法通过id获取特定人员。

+0

谢谢纳曼新的哈希表做的,采取了第二个方法和它的工作。 –

+0

欢迎您。如果它帮助你,那么你可以[接受](http://meta.stackexchange.com/q/5234/274278)它。 –

0

使用此代码通过ID获取特定用户。

List<Person> personsDetails = new Model.Finder(String.class,Person.class).all(); 

HashMap<String, Person> personMap = new HashMap<String, Person>(); 

for (Person product : personsDetails) { 
     if (product.id == id) { 
      personMap.put("CustomerAccount", product); 
     } 
} 

不要whateveryou想生成