Here is my simple User POCO class:
/// <summary> /// The User class represents a Coderwall User. /// </summary> public class User { /// <summary> /// A User username. eg: "sergiotapia, mrkibbles, matumbo" /// </summary> public string Username { get; set; } /// <summary> /// A User name. eg: "Sergio Tapia, John Cosack, Lucy McMillan" /// </summary> public string Name { get; set; } /// <summary> /// A User location. eh: "Bolivia, USA, France, Italy" /// </summary> public string Location { get; set; } public int Endorsements { get; set; } //Todo. public string Team { get; set; } //Todo. /// <summary> /// A collection of the User linked accounts. /// </summary> public List<Account> Accounts { get; set; } /// <summary> /// A collection of the User awarded badges. /// </summary> public List<Badge> Badges { get; set; } }
And the method that I use to deserialize the JSON response into a User object (this actual JSON call is here ):
private User LoadUserFromJson(string response) { var outObject = JsonConvert.DeserializeObject<User>(response); return outObject; }
This throws an exception:
It is not possible to deserialize the current JSON object (for example, {"name": "value"}) to type 'System.Collections.Generic.List`1 [CoderwallDotNet.Api.Models.Account] because it requires a JSON array (for example, [ 1,2,3]) for deserialization correctly.
To fix this error, either change the JSON to a JSON array (for example, [1,2,3]) or change the deserialized type so that it is a normal .NET type (for example, not a primitive type of integer type, but not a set of type like an array or a list) that can be deserialized from a JSON object. JsonObjectAttribute can also be added to a type to force it to deserialize from a JSON object. Accounts.github path, line 1, position 129.
I've never worked with this DeserializeObject method before, I'm kinda stuck here.
I made sure that the property names in the POCO class match the names in the JSON response.
What can I try to deserialize JSON in this POCO class?
json c # serialization poco
Only Bolivian Here Jun 20 '12 at 18:52 2012-06-20 18:52
source share