1 - Download the Newtonsoft JSON DLL (or set up a Nuget fetch)
2 - Add the reference to your project
3 - Create a class (Transaction) with properties that match the names of the JSON fields.
Conversion becomes:
Transaction t = Json.JsonConvert.DeserializeObject<Transaction>(the JSON string)
Examples and more detail on Newtonoft's site.
Deserialize an Object[
^]
In response to "don't understand" comment.
1 - The .Net framework doesn't (yet) have a library that provides easy translation from JSON string to C# object.
2 - Newtonsoft (follow link above to website and have poke around) provide a DLL (library). It is free to download. Download it. Get the right version for the version of .Net that you are using.
3 - Add a reference to the Newtonsoft DLL to your project, see MSDN if you don't know how to do this.
To use it:
We'll take just the first few fields in your JSON string to make the example simple.
{'Amount':16700000,'CardNumber':'0095','MerchantReference':'7654325'}
Create a class Transaction (or any other name that you choose) that has properties that match the names of the fields in your JSON string.
Class Transaction {
Public Long Amount {get; set;}
Public String CardNumber {get; set;}
Public String MerchantReference {get; set;}
}
And the code to convert is...
String json = @"{'Amount':16700000,'CardNumber':'0095','MerchantReference':'7654325'}";
Transaction t = Json.JsonConvert.DeserializeObject<Transaction>(json);
And the transaction object t will have the values you want.
Console.WriteLine(t.CardNumber);
Console.WriteLine(t.Amount);
Console.WriteLine(t.MerchantReference);