Advertisement
Guest User

Untitled

a guest
Sep 27th, 2016
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.61 KB | None | 0 0
  1. //wrapper class
  2. public class JSON2Apex
  3. {
  4. public Datetime DateModifiedUtc{get; set;}
  5. public List<AgentInfoList> AgentInfoList{get; set;}
  6. }
  7.  
  8. public class AgentInfoList
  9. {
  10. public String Username { get; set; }
  11. public Integer PriorityNumber { get; set; }
  12. }
  13.  
  14. public static JSON2Apex parse(String json)
  15. {
  16. return (JSON2Apex) System.JSON.deserialize(json, JSON2Apex.class);
  17. }
  18.  
  19. public CalloutAgentList()
  20. {
  21. info = (JSON2Apex)parse(helloKitty);
  22. system.debug('this is the string-->' + info);
  23. system.debug('this is the string-->' + info.AgentInfoList);
  24. system.debug('this is the string-->' + info.DateModifiedUtc);
  25. changeToPst = info.DateModifiedUtc;
  26. System.debug('This is the Converted Time to PST is ' + changeToPst.format('MM/dd/yyyy HH:mm:ss', 'America/Los_Angeles'));
  27. newDate = changeToPst.format('MM/dd/yyyy hh:mm aa' , 'America/Los_Angeles');
  28. }
  29.  
  30. static testMethod void testParse() {
  31. String json = '{"DateModifiedUtc":"2016-09-07T20:12:47.1519119Z","AgentInfoList":[{"Username":"Agent00@gmail.com","PriorityNumber":0},{"Username":"Agent01@gmail.com","PriorityNumber":0},{"Username":"Agent02@gmail.com","PriorityNumber":0},{"Username":"Agent03@gmail.com","PriorityNumber":0},{"Username":"Agent04@gmail.com","PriorityNumber":0},{"Username":"Agent05@gmail.com","PriorityNumber":0}]}';
  32. JSON2Apex obj = JSON2Apex.parse(json);
  33. System.assert(obj != null);
  34. }
  35.  
  36. WrapperClassName.JSON2Apex obj = WrapperClassName.JSON2Apex.parse(json);
  37.  
  38. public MyClass
  39. {
  40. public class JSON2Apex
  41. {
  42. //...
  43. }
  44. //...
  45. static JSON2Apex parse(String input)
  46. {
  47. //...
  48. }
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement