使用下面的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