1

I got this json:

[
   {
      "name":"Jon",
      "age":"34",
      "24_numeric_key":"somevalue"
   },
   {
      "name":"Mia",
      "age":"26",
      "24_numeric_key":"somevalue"
   },...
]

im able to deserialize this with:

List<Person> persons = JsonConvert.DeserializeObject<List<Person>>(json);

but with this i dont get the numeric value. How needs my class person to look like?

class Person:

class Person
{
   public string name { get; set; }
   public string age { get; set; }
   public string _24_numeric_key { get; set; }
}
Nkosi
  • 235,767
  • 35
  • 427
  • 472
Reeley
  • 105
  • 1
  • 11
  • 1
    Looks like a duplicate of [How to Deserialize an JSON object with invalid field name in it](https://stackoverflow.com/q/12215181). – dbc Dec 13 '17 at 23:06
  • Wow i searched for it and didnt find anything. Thanks bro this sounds promising i will try that – Reeley Dec 14 '17 at 07:33

1 Answers1

-2

Have you tried renaming you property inside your class to "24_numeric_key"? For proper deserialization the property names must match.

Edit:

People have pointed our a property cannot start with a number, so instead change your JSON data to include the "_" before the number so the property names match again.

Kevin
  • 1
  • 1