Click here to Skip to main content
15,893,487 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am trying to create an array of my object from JSON that I get from the Facebook Connect Graph API.

Here are my properties in my class:

C#
public string ID { get; set; }
public string Name { get; set; }


My Code:
XML
List<User> users = new List<User>();
Newtonsoft.Json.JsonConvert.PopulateObject(s, users);


The JSON:

XML
{"data":[{"name":"Friends Name","id":"000000"},{"name":"Other Friend","id":"000000"}]


The error I get is:

Cannot populate JSON object onto type 'System.Collections.Generic.List`1[FacebookConnectAPI.User]'.

Any help will be great, thanks!
Posted

1 solution

You'll find that there is another method PopulateObject that takes a third parameters of type JsonSerializerSettings. The information can be found here: http://james.newtonking.com/projects/json/help/[^]. Your type User has capitalized names whereas you Json string contains the names in lower case.

Cheers!

—MRB
 
Share this answer
 
Comments
DominicZA 7-Jul-11 2:19am    
I dont see anywhere where it has an option to ignore case?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900