user3248331
user3248331

Reputation: 105

Deserialize json object list with newton in c#

I have a json string that i am trying to deserialize into an object list using Newton. But it gives the

error Cannot deserialize the current JSON object (e.g. {"name":"value"}) into type 'System.Collections.Generic.List

The format of the json string is.

 [ { "key": "1", "value": "Package1" }, { "key": "some name", "value": "Package2" } ]

the Model is defined as

public class RootObject
{
    public string key { get; set; }
    public string value { get; set; }
}

And i'm using the following method to deserialize it, where json is the string listed above.

var resultList = JsonConvert.DeserializeObject<List<RootObject>>(json);

I'm not sure where i'm going wrong here, any help would be appreciated.

Upvotes: 0

Views: 515

Answers (1)

Priya Payyavula
Priya Payyavula

Reputation: 387

Try giving IDictionary instead of List.

Upvotes: 1

Related Questions