Guest User

Untitled

a guest
Jan 21st, 2019
311
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.49 KB | None | 0 0
  1. {"books":[
  2. {
  3. "title": "The Adventures in JSON",
  4. ...
  5. "publisher": "New York Publisher Ltd",
  6. "author": {
  7. "name": "Freddie Jsonwood",
  8. "nationality": "Some Nationality",
  9. ...
  10. }
  11. },{
  12. "title": "Psychology Treatment Of Confused Developers After JSON Exposure",
  13. ...
  14. "publisher": "San Francisco Publisher Ltd",
  15. "author": {
  16. "name": "Abraham Jsonwall",
  17. "nationality": "Some Nationality",
  18. ...
  19. }
  20. },...
  21. ]
  22. }
  23.  
  24. JsonArray items = (JsonArray)rootitems["rootitems"];
  25.  
  26. var query = (from item in items select new Book
  27. {
  28. Title = item["title"],
  29. Publisher = item["publisher"],
  30. ...
  31. BookUrl = item["bookurl"],
  32. // The above code is easy and works
  33. // Now I don't know how to do it
  34. // I can have ONLY one author,
  35. // so I'd like to do something like this
  36. AuthorName = item["author"]["name"],
  37. AuthorNationality = item["author"]["nationality"],
  38.  
  39. ...
  40.  
  41. }
  42.  
  43. Book
  44. public string Title
  45. public string Publisher
  46. public string AuthorName
  47. public string AuthorNationality
  48.  
  49. var query = (from item in items select new Book
  50. {
  51. Title = item["title"],
  52. Publisher = item["publisher"],
  53. ...
  54. BookUrl = item["bookurl"],
  55. // Now I don't know how to do it
  56. // Author is a class and, in my case,
  57. // I can have ONLY one author,
  58. // so I'd like to do something like this
  59. Author = (from a item["author"] select new Author
  60. {
  61. AuthorName = a["name"],
  62. AuthorNationality = a["nationality"],
  63. ...
  64. }
  65.  
  66. ...
  67.  
  68. }
  69.  
  70. Book
  71. public string Title
  72. public string Publisher
  73. public Author Author
  74.  
  75. Author
  76. public string Name
  77. public string Nationality
Add Comment
Please, Sign In to add comment