使用下面的url我想拉动追随者,一个特定的屏幕名称有哪些工作正常。当我尝试将代码反序列化为ojbect时,我会在下面的任何想法的原因获取错误消息。我也把代码为Json类型..我想获得位置提交。我发布了用户本身就是一个对象。所以我可以得到一个例子,让我脱盐的初始对象,然后内部的对象。反序列化json twitter字符串到对象
URL = "https://api.twitter.com/1.1/followers/list.json?&screen_name="will insert here "
反序列化为objec代码
var result = JsonConvert.DeserializeObject<List>(FollowerData)
的Json类型代码
public class Follower
{
[JsonProperty("created_at")]
public string CreatedAt { get; set; }
[JsonProperty("id")]
public string Id { get; set; }
[JsonProperty("id_str")]
public string IdStr { get; set; }
[JsonProperty("name")]
public string Name { get; set; }
[JsonProperty("screen_name")]
public string ScreenName { get; set; }
[JsonProperty("location")]
public bool Location { get; set; }
[JsonProperty("description")]
public string Description { get; set; }
}
错误消息
{“不能反序列化当前JSON对象(例如 {\“name \”:\“value \”})转换为 'System.Collections.Generic.List`1 [OAuthTwitterWrapper.JsonTypes.FollowerUsers]' ,因为该类型需要JSON数组(例如, [1,2,3])以正确反序列化 。\ r \ n要修复此错误,请将JSON更改为JSON数组(例如[1,2,3])或更改反序列化类型以使其成为正常 .NET类型(例如,不是类似于整数的基元类型,而不是类似数组或列表的集合 类型)可以从JSON 对象反序列化。 JsonObjectAttribute也可以添加到该类型迫使它从 JSON对象反序列化。\ r \ n路径 '用户',第1行,位置 9“}
JSON字符串Examplt
{
"users": [
{
"id": 219566993,
"id_str": "219566993",
"name": "belenastorgano",
"screen_name": "anna_belenn_",
"location": "CapitalFederal, Argentina",
"description": "Mesientonomade, todav\\u00edanotengounlugarfijodondevivir.-",
"url": null,
"entities": {
"description": {
"urls": []
}
},
"protected": true,
"followers_count": 44,
"friends_count": 64,
"listed_count": 0,
"created_at": "ThuNov2506: 28: 12+00002010",
"favourites_count": 1,
"utc_offset": -10800,
"time_zone": "BuenosAires",
"geo_enabled": true,
"verified": false,
"statuses_count": 207,
"lang": "es",
"contributors_enabled": false,
"is_translator": false,
"profile_background_color": "599E92",
"profile_background_image_url": "http: \\/\\/a0.twimg.com\\/images\\/themes\\/theme18\\/bg.gif",
"profile_background_image_url_https": "https: \\/\\/si0.twimg.com\\/images\\/themes\\/theme18\\/bg.gif",
"profile_background_tile": false,
"profile_image_url": "http: \\/\\/a0.twimg.com\\/profile_images\\/378800000326157070\\/e91b8fd8e12eda0a7fa350dcd286c56a_normal.jpeg",
"profile_image_url_https": "https: \\/\\/si0.twimg.com\\/profile_images\\/378800000326157070\\/e91b8fd8e12eda0a7fa350dcd286c56a_normal.jpeg",
"profile_link_color": "E05365",
"profile_sidebar_border_color": "EEEEEE",
"profile_sidebar_fill_color": "F6F6F6",
"profile_text_color": "333333",
"profile_use_background_image": true,
"default_profile": false,
"default_profile_image": false,
"following": null,
"follow_request_sent": null,
"notifications": null
}
],
"next_cursor": 1443863551966642400,
"next_cursor_str": "1443863551966642309",
"previous_cursor": 0,
"previous_cursor_str": "0"
}
将示例json字符串放入此站点:http://json2csharp.com/ 查看类结构是否匹配。 – stevepkr84
它没有在该网站上工作。并且我正在创建我自己的json类型 –
*'它不适合在该网站上工作。并且我正在创建自己的json类型。*它认为你不知道你在做什么。我粘贴你的示例json到该网站,并使用它创建的类,如**'var followerData = JsonConvert.DeserializeObject(json); Console.WriteLine(followerData.users [0] .location);'**。 ** **田田。它的工作..... –
I4V