I am reading Json files and populate List of Items using Newtonsoft.Json. I have a problem reading some Json files were the name of the attribute has spaces and therefore it is not the same as the attributes of Item class.
This is fine. Item object will assigned with the below values.
[
{
"FirstName": "John",
"SecondName": "Smith"
}
]
But my Json file is like this thus Item object has null values for FirstName and SecondName
[
{
"First Name": "John",
"Second Name": "Smith"
}
]
Therefore my Item which has properties of FirstName and SecondName (see below) will get a null value.
public class Item
{
private string firstName = "";
private string secondName = "";
public string FirstName
{
get { return firstName; }
set { firstName = value; }
}
public string SecondName
{
get { return secondName; }
set { secondName = value; }
}
}
Is there a simple way how to solve this problem. I have no control on the namings (e.g. FirstName or First Name in the Json string.
Aucun commentaire:
Enregistrer un commentaire