Ranking.cs 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. using Newtonsoft.Json.Linq;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Web;
  6. namespace NEducation.Code
  7. {
  8. public class Ranking
  9. {
  10. public List<RankingElement> listRanking { get; set; }
  11. // parse data from JSON data
  12. public Ranking() { }
  13. public Ranking(string json) : this(JObject.Parse(json))
  14. { }
  15. public Ranking(JObject jObject)
  16. {
  17. if (jObject != null)
  18. {
  19. var list = jObject["LIST_RANKING"];
  20. if (list != null && list.HasValues)
  21. {
  22. listRanking = new List<RankingElement>();
  23. JArray a = (JArray)list;
  24. foreach (JObject o in a.Children<JObject>())
  25. {
  26. listRanking.Add(new RankingElement(o));
  27. }
  28. }
  29. }
  30. }
  31. }
  32. public class RankingElement
  33. {
  34. public string seq { get; set; }
  35. public string usersId { get; set; }
  36. public string users { get; set; }
  37. public string msisdn { get; set; }
  38. public string serviceId { get; set; }
  39. public string fullName { get; set; }
  40. public string birthday { get; set; }
  41. public string picture { get; set; }
  42. public string totalScore { get; set; }
  43. // parse data from JSON data
  44. public RankingElement() { }
  45. public RankingElement(string json) : this(JObject.Parse(json))
  46. { }
  47. public RankingElement(JObject jObject)
  48. {
  49. if (jObject != null)
  50. {
  51. seq = (string)jObject["SEQ"];
  52. usersId = (string)jObject["USERS_ID"];
  53. users = (string)jObject["USERS"];
  54. msisdn = (string)jObject["MSISDN"];
  55. serviceId = (string)jObject["SERVICE_ID"];
  56. fullName = (string)jObject["FULLNAME"];
  57. birthday = (string)jObject["BIRTHDAY"];
  58. String myString = (string)jObject["BIRTHDAY"]; // get value from text field
  59. DateTime myDateTime = new DateTime();
  60. myDateTime = DateTime.ParseExact(myString, "dd/MM/yyyy HH:mm:ss", null);
  61. String myString_new = myDateTime.ToString("dd-MM-yyyy");
  62. birthday = myString_new;
  63. picture = (string)jObject["PICTURE"];
  64. totalScore = (string)jObject["TOTAL_SCORE"];
  65. }
  66. }
  67. }
  68. }