I have JSON object received from a website and store it in a string value.I have generated the necessary classes to map to the JSON obejct.My question is how then do I get to assign the value of JSON to the class properties/variables
JSON data:
{
"echo_req": {
"subscribe": 1,
"transaction": 1
},
"msg_type": "transaction",
"transaction": {
"action": "buy",
"amount": "-250.0000",
"balance": "530800.61",
"contract_id": "108 32430388",
"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": "215802164 88",
"transaction_time": 1478241435
}
}
C# class:
namespace BinaryData
{
public class Echo_Req
{
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 Echo_Req echo_req { get; set; }
public string msg_type { get; set; }
public Transaction transaction { get; set; }
}
}
In program I have but getting stuck in how i assign the contract ID
var str = Encoding.UTF8.GetString(buffer.Array, 0, result.Count);//
Console.WriteLine(str);//prints json correctly
Transaction tradeDetails = new Transaction();
tradeDetails.contract_id=str.contract_id//How do I do this
Also just a side note would this be the effective way of getting the values to write the code to store in SQL.I will be using ADO.NET becasue simply dont know EF yet