无法从JSON创建数组 [英] Cant create an array from JSON

查看:68
本文介绍了无法从JSON创建数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试根据从Facebook Connect Graph API获得的JSON创建对象数组.

这是我在课堂上的属性:

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:

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



我的代码:



My Code:

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



JSON:



The JSON:

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



我得到的错误是:

无法将JSON对象填充到"System.Collections.Generic.List`1 [FacebookConnectAPI.User]"类型上.



The error I get is:

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

Any help will be great, thanks!

推荐答案

您会发现,还有另一种方法PopulateObjec t带有类型为JsonSerializerSettings的第三个参数.该信息可以在这里找到: http://james.newtonking.com/projects/json/help/ [ ^ ].您的类型User具有大写的名称,而您的Json字符串包含小写的名称.

干杯!

—MRB
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


这篇关于无法从JSON创建数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆