0

I am creting API for working with JSON input and storing. This is json format that I need to insert:

{
"user_id": 1,
"amount": 1,
"paging": {
"skip": 6,
"take": 10
},
"name": "Test"
}

It stores "paging" as null. Here is my c# code:

{

    public class TodoItem
    {
        [Key]
        public long User_id { get; set; }
        public int Amount { get; set; }
        public Paging Paging { get; set; }
        public string Name { get; set; }

    }

    public class Paging
    {
        [Key]
        public int Skip { get; set; }
        public int Take { get; set; }
    }
}

I was getting an error until I did not put [Key] tags, but I think something is wrong with that as well. Thank you!

matara98
  • 3
  • 2
  • 1
    It would help if you mentioned the library you are using for the serialization and the error that you are getting. Also it would help to include the code that invokes the serializer. – Natalia Muray Feb 12 '21 at 13:00
  • Most likely the library you are using (Newtonsoft?) is case-sensitive. – Charlieface Feb 12 '21 at 13:07
  • What is the "rest of variable", what do you see in debugger? – Charlieface Feb 12 '21 at 13:09
  • Umm, Im not sure about the serialization library. I followed the tutorial and just changed it to my data type. https://learn.microsoft.com/en-us/aspnet/core/tutorials/first-web-api?view=aspnetcore-5.0&tabs=visual-studio – matara98 Feb 12 '21 at 13:12

1 Answers1

1

Serialization/Deserialization is case sensitive.

var options = new JsonSerializerOptions
{
    PropertyNameCaseInsensitive = true,
};
Seeds
  • 372
  • 2
  • 14