Grammar.cs 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. using NEducation.Controllers;
  2. using Newtonsoft.Json.Linq;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using System.Web;
  7. namespace NEducation.Code
  8. {
  9. public class Grammar
  10. {
  11. public String id { get; set; }
  12. public String name { get; set; }
  13. public String description { get; set; }
  14. public String introduction { get; set; }
  15. //public String example { get; set; }
  16. //public String content { get; set; }
  17. //public String contentType { get; set; }
  18. public String picture { get; set; }
  19. public String lessonID { get; set; }
  20. public List<GrammarExample> listGrammarExample { get; set; }
  21. // parse data from JSON data
  22. public Grammar() { }
  23. public Grammar(string json) : this(JObject.Parse(json))
  24. { }
  25. public Grammar(JObject jObject)
  26. {
  27. if (jObject != null)
  28. {
  29. id = (string)jObject["ID"];
  30. name = (string)jObject["NAME"];
  31. description = (string)jObject["DESCRIPTION"];
  32. introduction = (string)jObject["INTRODUCTION"];
  33. picture = UtilsController.GetContentPath.GrammarContentPath + (string)jObject["PICTURE"];
  34. lessonID = (string)jObject["LESSON_ID"];
  35. //contentType = (string)jObject["CONTENT_TYPE"];
  36. //if (contentType == UtilsController.GetContentType.AUDIO_FILE ||
  37. // contentType == UtilsController.GetContentType.PICTURE_FILE ||
  38. // contentType == UtilsController.GetContentType.VIDEO_FILE)
  39. // content = UtilsController.GetContentPath.GrammarContentPath + (string)jObject["CONTENT"];
  40. //else
  41. // content = (string)jObject["CONTENT"];
  42. var list = jObject["LIST_GRAMMAR_EX"];
  43. if (list != null && list.HasValues)
  44. {
  45. listGrammarExample = new List<GrammarExample>();
  46. JArray a = (JArray)list;
  47. foreach (JObject o in a.Children<JObject>())
  48. {
  49. listGrammarExample.Add(new GrammarExample(o));
  50. }
  51. }
  52. }
  53. }
  54. }
  55. }