Riven Joy

Riven Joy

  • NA
  • 64
  • 1.5k

Json data to separate variables for saving in DB

Nov 4 2016 3:03 AM
I have a console application which receives data from a website
The format of the returned JSon data which is stored in a string is:
 
 
{ "echo_req":{ "subscribe":1,"transaction":1},"msg_type":"transac tion","transaction":{ "action":"buy","amount":"-250.0000","balance":"530800.61","contract_id":"108 32430388","currency":"USD","date_expiry":147824233 5," display_name":"Volatility 10 Index","id":"de7cc6e6-218c-86a5-805f-093c1176f605","longcode":"Win payout if Volatility 10 Index is strictly lower than entry spot at 15 minutes after contract start time.","symbol":"R_10","transaction_id":"215802164 88","transaction_time":1478241435}}
 
 
 
How can I make the Json into separate variables or class object so that i can save them in the database.
 

To further add I found a json2csharp. I am more interested in saving the data in the Transaction class but don't know what to do from here:

  1. publicclassEchoReq  
  2. {  
  3. publicint subscribe {get;set;}  
  4. publicint transaction {get;set;}  
  5. }  
  6.   
  7. publicclassTransaction  
  8. {  
  9. publicstring action {get;set;}  
  10. publicstring amount {get;set;}  
  11. publicstring balance {get;set;}  
  12. publicstring contract_id {get;set;}  
  13. publicstring currency {get;set;}  
  14. publicint date_expiry {get;set;}  
  15. publicstring display_name {get;set;}  
  16. publicstring id {get;set;}  
  17. publicstring longcode {get;set;}  
  18. publicstring symbol {get;set;}  
  19. publicstring transaction_id {get;set;}  
  20. publicint transaction_time {get;set;}  
  21. }  
  22.   
  23. publicclassRootObject  
  24. {  
  25. publicEchoReq echo_req {get;set;}  
  26. publicstring msg_type {get;set;}  
  27. publicTransaction transaction {get;set;}  
  28.   
  29. }  
 

Answers (4)