Guest User

Untitled

a guest
Nov 15th, 2017
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.75 KB | None | 0 0
  1. {
  2. "transactions":
  3. [
  4. {
  5. "paymentcharge":"0.0",
  6. "amount":352,
  7. "id":13418,
  8. "shippingcharge":35,
  9. "shippingtype":2,
  10. "status":2,
  11. "paymenttype":1,
  12. "date":"2012-10-06 16:15:28.0"
  13. },
  14. {
  15. "paymentcharge":"0.0",
  16. "amount":42455,
  17. "id":16305,
  18. "shippingcharge":0,
  19. "shippingtype":2,
  20. "status":2,
  21. "paymenttype":2,
  22. "date":"2012-11-30 09:29:29.0"
  23. },
  24. {
  25. "paymentcharge":"1.0",
  26. "amount":42456,
  27. "id":16305,
  28. "shippingcharge":0,
  29. "shippingtype":2,
  30. "status":2,
  31. "paymenttype":2,
  32. "date":"2012-11-30 09:29:29.0"
  33. }
  34. ],
  35. "count":3
  36. }
  37.  
  38. class clsSalesTran
  39. {
  40. public double paymentcharge { get; set; }
  41. public double amount { get; set; }
  42. public long id { get; set; }
  43. public int shippingcharge { get; set; }
  44. public int shippingtype { get; set; }
  45. public int status { get; set; }
  46. public int paymenttype { get; set; }
  47. public DateTime date { get; set; }
  48. }
  49.  
  50. public class SalesTransactions
  51. {
  52. public List<clsSalesTran> transactions {get;set;}
  53. public int count{get;set;}
  54. }
  55.  
  56. JsonConvert.DeserializeObject<SalesTransactions>(inputString)
  57.  
  58. public class SalesTransactions
  59. {
  60. [JsonProperty("transactions")]
  61. public List<clsSalesTran> transactions {get;set;}
  62. public int count{get;set;}
  63. }
  64.  
  65. SalesTransactions st = JsonConvert.DeserializeObject<SalesTransactions>(inputString)
  66.  
  67. double paymentcharge = st.transactions[0].paymentcharge;
  68.  
  69. class WeapsCollection
  70. {
  71. public Dictionary<string, WeaponDetails> Weapons { get; set; }
  72.  
  73. }
  74.  
  75. class WeaponList
  76. {
  77. public WeaponDetails AEK { get; set; }
  78. public WeaponDetails XM8 { get; set; }
  79. }
  80.  
  81. class WeaponDetails
  82. {
  83. public string Name { get; set; }
  84. public int Kills { get; set; }
  85. public int Shots_Fired { get; set; }
  86. public int Shots_Hit { get; set; }
  87. }
  88.  
  89. class Program
  90. {
  91. static void Main(string[] args)
  92. {
  93. string json = @"
  94. {
  95. 'weapons':
  96.  
  97. {
  98. 'aek':
  99. {
  100. 'name':'AEK-971 Vintovka',
  101. 'kills':47,
  102. 'shots_fired':5406,
  103. 'shots_hit':858
  104. },
  105. 'xm8':
  106. {
  107. 'name':'XM8 Prototype',
  108. 'kills':133,
  109. 'shots_fired':10170,
  110. 'shots_hit':1790
  111. },
  112. }
  113.  
  114. }";
  115.  
  116. WeapsCollection weps = JsonConvert.DeserializeObject<WeapsCollection>(json);
  117. Console.WriteLine(weps.Weapons.First().Value.Shots_Fired);
  118.  
  119. Console.ReadLine();
  120.  
  121. }
  122. }
Add Comment
Please, Sign In to add comment