Advertisement
Guest User

Untitled

a guest
Sep 26th, 2017
43
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.75 KB | None | 0 0
  1. [
  2. {
  3. "fullName": "a",
  4. "password": "a",
  5. "roles": [
  6. {
  7. "role_id": "dilbert"
  8. },
  9. {
  10. "roleId": "admin"
  11. }
  12. ]
  13. }
  14. ]
  15.  
  16. public static User fromJson(JSONObject json) throws JSONException {
  17. User u = new User();
  18. u.setFullName(json.getString("fullName"));
  19. u.setPassword(json.getString("password"));
  20.  
  21. JSONArray array = json.getJSONArray("roles");
  22. for(int i=0; i < array.length(); i++){
  23. JSONObject o = array.getJSONObject(i);
  24. Role r = Role.fromJson(o);
  25.  
  26. }
  27.  
  28. return u;
  29. }
  30.  
  31. public static Role fromJson(JSONObject json) throws JSONException {
  32. Role r = new Role();
  33. r.setRole_id(json.getString("roles"));
  34. return r;
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement