Currently, I am working on creating a dictionary for indexing JSON values with strings. To achieve this, I am utilizing Newtonsoft to deserialize the JSON string. Here is an example of my JSON data:
{
"financialPositions": [
{
"fieldName": "Assets",
"periodEndToDateValue": 0.0,
"pastYearEndToDateValue": 0.0,
"description": "\u062f\u0627\u0631\u0627\u06cc\u06cc\u200c\u200c\u0647\u0627",
"percentChanges": 0.0,
"rowClass": "GroupHeader"
},
{
"rowClass": "ComputationalRow",
"fieldName": "ListedCapital",
"description": "\u0633\u0631\u0645\u0627\u06cc\u0647",
"percentChanges": 0.0,
"currentPeriodEndToDateValue": 1.0,
"pastSimillarEndToDateValue": 1.0,
"pastYearEndToDateValue": 1.0
}
]
}
The classes I have used are as follows:
public class RootObject
{
public FinancialPositions[] financialPositions{ get; set; }
}
public class FinancialPositions
{
public string fieldName { get; set; }
public double periodEndToDateValue { get; set; }
public double pastYearEndToDateValue { get; set; }
public string description { get; set; }
public float percentChanges { get; set; }
public string rowClass { get; set; }
}
To deserialize the JSON string, I use the following code snippet:
RootObject oRootObject = new RootObject();
oRootObject = JsonConvert.DeserializeObject<RootObject>(jsonstring);
If you want to make changes to access specific parts of the deserialized object, you can do so by addressing them like below:
oRootObject.financialPositions["Assets"]