Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- String string=new String("[{\"id\":\"2018\",\"ceaNumber\":\"R000001X\",\"fullName\":\"Ang Ah Boon\"},{\"id\":\"2019\",\"ceaNumber\":\"R000002X\",\"fullName\":\"Ang Ah Boon 2\"}]");
- try {
- JSONArray jsonArr = new JSONArray(string);
- HashMap<String,User> users = new HashMap<String,User>();
- for (int i = 0; i < jsonArr.length(); i++)
- {
- JSONObject jsonObj = jsonArr.getJSONObject(i);
- Iterator iterator = jsonObj.keys();
- String id = null;
- User u=new User();
- while(iterator.hasNext()){
- String key = (String) iterator.next();
- if(key.equals("id")){
- id=(String) jsonObj.get(key);
- u.id=id;
- }
- if(key.equals("ceaNumber")){
- u.ceaNumber=(String)jsonObj.get(key);
- }
- if(key.equals("fullName")){
- u.fullName=(String)jsonObj.get(key);
- }
- }
- users.put(id,u);
- }
- System.out.println(users);
- } catch (JSONException e) {
- e.printStackTrace();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement