1

I have a very simple POCO class:

    [JsonArray]
    public class WebGame
    {    
        public  int Key { get; set; }

        public string Name { get; set; }

        public string Description { get; set; }
    }

Trying to deserialize to it a json string:

  string json = @"[{'Key':'1','Name':'WebGame','Description':'bla-bla-bla'}]";
  var myDeserializedObjList = (List<WebGame>)(JsonConvert.DeserializeObject(json, typeof(List<WebGame>)));      
  var game = myDeserializedObjList[0];

I get an exception:

Cannot deserialize the current JSON object (e.g. {"name":"value"}) into type 'WebGame' because the type requires a JSON array (e.g. [1,2,3]) to deserialize correctly. To fix this error either change the JSON to a JSON array (e.g. [1,2,3]) or change the deserialized type so that it is a normal .NET type (e.g. not a primitive type like integer, not a collection type like an array or List) that can be deserialized from a JSON object. JsonObjectAttribute can also be added to the type to force it to deserialize from a JSON object.

What's wrong here?

1 Answer 1

1

Remove [JsonArray] attribute and it would work fine

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.