ListLessonData.cs 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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 ListLessonData
  9. {
  10. public string status { get; set; }
  11. public string message { get; set; }
  12. public List<Vocabulary> vocabularies { get; set; }
  13. public List<Grammar> grammars { get; set; }
  14. public List<Listening> listenings { get; set; }
  15. public List<Question> questions { get; set; }
  16. // parse data from JSON data
  17. public ListLessonData() { }
  18. public ListLessonData(string json) : this(JObject.Parse(json))
  19. { }
  20. public ListLessonData(JObject jObject)
  21. {
  22. if (jObject != null)
  23. {
  24. status = (string)jObject["status"];
  25. message = (string)jObject["message"];
  26. var listVocab = jObject["LIST_VOCABULARY"];
  27. if (listVocab != null && listVocab.HasValues)
  28. {
  29. vocabularies = new List<Vocabulary>();
  30. JArray a = (JArray)listVocab;
  31. foreach (JObject o in a.Children<JObject>())
  32. {
  33. vocabularies.Add(new Vocabulary(o));
  34. }
  35. }
  36. var listListen = jObject["LIST_LISTEN"];
  37. if (listListen != null && listListen.HasValues)
  38. {
  39. listenings = new List<Listening>();
  40. JArray a = (JArray)listListen;
  41. foreach (JObject o in a.Children<JObject>())
  42. {
  43. listenings.Add(new Listening(o));
  44. }
  45. }
  46. var listGrammar = jObject["LIST_GRAMMAR"];
  47. if (listGrammar != null && listGrammar.HasValues)
  48. {
  49. grammars = new List<Grammar>();
  50. JArray a = (JArray)listGrammar;
  51. foreach (JObject o in a.Children<JObject>())
  52. {
  53. grammars.Add(new Grammar(o));
  54. }
  55. }
  56. var listQuestion = jObject["LIST_QUESTION"];
  57. if (listQuestion != null && listQuestion.HasValues)
  58. {
  59. questions = new List<Question>();
  60. JArray a = (JArray)listQuestion;
  61. foreach (JObject o in a.Children<JObject>())
  62. {
  63. questions.Add(new Question(o));
  64. }
  65. }
  66. }
  67. }
  68. }
  69. }