Advertisement
Guest User

Untitled

a guest
Apr 15th, 2014
223
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.36 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Net;
  5. using System.Windows;
  6. using System.Windows.Controls;
  7. using System.Windows.Navigation;
  8. using Microsoft.Phone.Controls;
  9. using Microsoft.Phone.Shell;
  10. using PhoneApp5.Resources;
  11. using Newtonsoft.Json;
  12.  
  13. namespace PhoneApp5
  14. {
  15. public partial class MainPage : PhoneApplicationPage
  16. {
  17. // Constructor
  18. public MainPage()
  19. {
  20. InitializeComponent();
  21.  
  22.  
  23.  
  24. string jsona = @"[
  25. {
  26. 'Name': 'Product 1',
  27. 'ExpiryDate': '2000-12-29T00:00Z',
  28. 'Price': 99.95,
  29. 'Sizes': null
  30. },
  31. {
  32. 'Name': 'Product 2',
  33. 'ExpiryDate': '2009-07-31T00:00Z',
  34. 'Price': 12.50,
  35. 'Sizes': null
  36. }
  37. ]";
  38.  
  39. List<Product> products = JsonConvert.DeserializeObject<List<Product>>(jsona);
  40.  
  41. //Console.WriteLine(products.Count);
  42. // 2
  43.  
  44. Product p1 = products[0];
  45. Product p2 = products[1];
  46.  
  47. MessageBox.Show(p1.Name);
  48. MessageBox.Show(p2.Name);
  49.  
  50. // Product 1
  51.  
  52. }
  53.  
  54.  
  55.  
  56. }
  57.  
  58. public class Product
  59. {
  60. public string Name { get; set; }
  61. public DateTime ExpiryDate { get; set; }
  62. public string Price { get; set; }
  63. public string Sizes { get; set; }
  64.  
  65. }
  66.  
  67.  
  68.  
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement