0

i have the following json array

  [
    {
      "Name ": "name1",
      "Abbreviation ": "abb1"
    },
    {
      "Name ": "name2",
      "Abbreviation ": "abb2"
    }
  
  ]

and the following C# class

  public class AbbriviationKey
    {
        public string Name { get; set; }
        public string Abbreviation { get; set; }
    }

when i try to deserialize the json array into List<AbbriviationKey> using the following code:

    string json = File.ReadAllText("jsonFile.json");
            var abbriviationKeys = JsonConvert.DeserializeObject<List<AbbriviationKey>>(json);

properties of each AbbriviationKey are set to null:

enter image description here

1 Answer 1

2

You have a space in the key name in your json.

Try with this:

[
    {
      "Name": "name1",
      "Abbreviation": "abb1"
    },
    {
      "Name": "name2",
      "Abbreviation": "abb2"
    }
]
Sign up to request clarification or add additional context in comments.

1 Comment

wow i can't believe it, i was stuck in this for hours, hahaha thank you

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.