I have ran into an issue while pulling data down from an API (Not mine and I can't change the way its formatted) and then mapping that onto a C# List.
A small sample of the JSON looks like this (There are thousands of records in the form_values section and thousands of records)
JSON Sample:
{
"records":[
{
"status":"4",
"version":5,
"form_values":{
"4015":"TextValue",
"5919":"TextValue",
"6127":"TextValue",
"7868":"0",
"q311":"TextValue",
"r83b":"0"
}
}
],
"current_page":1,
"total_pages":1,
"total_count":1,
"per_page":12
}
Currently I am putting the JSON result into a strongly typed list with the following code (This uses Newtonsoft.Json):
C# JSON Deserialize to List
JsonConvert.DeserializeObject<Data>(json_data);
It is in the Data.cs Class that I am having issues as C# will not allow a variable to start with a int.
What I have tried, with no success is using the Runtime.Serilization DataMember
attribute.
Data.cs
[DataMember(Name = "4015")]
public string textfeild { get; set; }
The Issue:
This results in a null value being set regardless of data behind. All of the fields that start with a letter work fine, so I am confident my JSON is being written to the List correctly, just need a solution for these annoying ID's that start with a number!
Any help would be much appreciated.