Winner.cs 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. using Newtonsoft.Json.Linq;
  2. using System.Collections.Generic;
  3. namespace NEducation.Code
  4. {
  5. public class Winner
  6. {
  7. public List<WinnerElement> listWinner { get; set; }
  8. // Default constructor
  9. public Winner() { }
  10. // Constructor that parses JSON string
  11. public Winner(string json) : this(JObject.Parse(json)) { }
  12. // Constructor that parses JObject
  13. public Winner(JObject jObject)
  14. {
  15. if (jObject != null)
  16. {
  17. var list = jObject["listWinner"];
  18. if (list != null && list.HasValues)
  19. {
  20. listWinner = new List<WinnerElement>();
  21. JArray a = (JArray)list;
  22. foreach (JObject o in a.Children<JObject>())
  23. {
  24. listWinner.Add(new WinnerElement(o));
  25. }
  26. }
  27. }
  28. }
  29. }
  30. public class WinnerElement
  31. {
  32. public string id { get; set; }
  33. public string userId { get; set; }
  34. public string lestionId { get; set; }
  35. public string totalQuestion { get; set; }
  36. public string totalFalse { get; set; }
  37. public string totalTrue { get; set; }
  38. public string totalTime { get; set; }
  39. public string totalScore { get; set; }
  40. public string sysdate { get; set; }
  41. public string termId { get; set; }
  42. public string msisdn { get; set; }
  43. // Default constructor
  44. public WinnerElement() { }
  45. // Constructor that parses JSON string
  46. public WinnerElement(string json) : this(JObject.Parse(json)) { }
  47. // Constructor that parses JObject
  48. public WinnerElement(JObject jObject)
  49. {
  50. if (jObject != null)
  51. {
  52. id = (string)jObject["id"];
  53. userId = (string)jObject["userId"];
  54. lestionId = (string)jObject["lestionId"];
  55. totalQuestion = (string)jObject["totalQuestion"];
  56. totalFalse = (string)jObject["totalFalse"];
  57. totalTrue = (string)jObject["totalTrue"];
  58. totalTime = (string)jObject["totalTime"];
  59. totalScore = (string)jObject["totalScore"];
  60. sysdate = (string)jObject["sysdate"];
  61. termId = (string)jObject["termId"];
  62. msisdn = (string)jObject["msisdn"];
  63. }
  64. }
  65. }
  66. }