Json data to separate variables for saving in DB

riven

New member
Joined
Nov 4, 2016
Messages
1
Programming Experience
Beginner
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":"transaction","transaction":{ "action":"buy","amount":"-250.0000","balance":"530800.61","contract_id":"10832430388","currency":"USD","date_expiry":1478242335," 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":"21580216488","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:
public class EchoReq
{
public int subscribe { get; set; }
public int transaction { get; set; }
}

public class Transaction
{
public string action { get; set; }
public string amount { get; set; }
public string balance { get; set; }
public string contract_id { get; set; }
public string currency { get; set; }
public int date_expiry { get; set; }
public string display_name { get; set; }
public string id { get; set; }
public string longcode { get; set; }
public string symbol { get; set; }
public string transaction_id { get; set; }
public int transaction_time { get; set; }
}

public class RootObject
{
public EchoReq echo_req { get; set; }
public string msg_type { get; set; }
public Transaction transaction { get; set; }
}
 
Last edited:
Back
Top Bottom