首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >无法从System.Int64转换或转换为System.Collections.Generic.List

无法从System.Int64转换或转换为System.Collections.Generic.List
EN

Stack Overflow用户
提问于 2013-07-05 20:05:45
回答 1查看 2.8K关注 0票数 0

当我试图从Twitter API反序列化JSON响应时,我得到了以下异常。它有时会经历,但有时会有问题。

下面是几个类:

代码语言:javascript
运行
复制
public static List<Tweet> Newtwt = new List<Tweet>();

public class Url2
{
    public string url { get; set; }
    public string expanded_url { get; set; }
    public string display_url { get; set; }
    public List<int> indices { get; set; }
}

public class Url
{
    public List<Url2> urls { get; set; }
}

public class Description
{
    public List<object> urls { get; set; }
}

public class Entities
{
    public Url url { get; set; }
    public Description description { get; set; }
}

public class User
{
    public int id { get; set; }
    public string id_str { get; set; }
    public string name { get; set; }
    public string screen_name { get; set; }
    public string location { get; set; }
    public string description { get; set; }
    public string url { get; set; }
    public Entities entities { get; set; }
    public bool @protected { get; set; }
    public int followers_count { get; set; }
    public int friends_count { get; set; }
    public int listed_count { get; set; }
    public string created_at { get; set; }
    public int favourites_count { get; set; }
    public int utc_offset { get; set; }
    public string time_zone { get; set; }
    public bool geo_enabled { get; set; }
    public bool verified { get; set; }
    public int statuses_count { get; set; }
    public string lang { get; set; }
    public bool contributors_enabled { get; set; }
    public bool is_translator { get; set; }
    public string profile_background_color { get; set; }
    public string profile_background_image_url { get; set; }
    public string profile_background_image_url_https { get; set; }
    public bool profile_background_tile { get; set; }
    public string profile_image_url { get; set; }
    public string profile_image_url_https { get; set; }
    public string profile_link_color { get; set; }
    public string profile_sidebar_border_color { get; set; }
    public string profile_sidebar_fill_color { get; set; }
    public string profile_text_color { get; set; }
    public bool profile_use_background_image { get; set; }
    public bool default_profile { get; set; }
    public bool default_profile_image { get; set; }
    public object following { get; set; }
    public bool follow_request_sent { get; set; }
    public object notifications { get; set; }
}

public class Entities2
{
    public List<object> hashtags { get; set; }
    public List<object> symbols { get; set; }
    public List<object> urls { get; set; }
    public List<object> user_mentions { get; set; }
}

public class RootObject
{
    public string created_at { get; set; }
    public object id { get; set; }
    public string id_str { get; set; }
    public string text { get; set; }
    public string source { get; set; }
    public bool truncated { get; set; }
    public object in_reply_to_status_id { get; set; }
    public object in_reply_to_status_id_str { get; set; }
    public object in_reply_to_user_id { get; set; }
    public object in_reply_to_user_id_str { get; set; }
    public object in_reply_to_screen_name { get; set; }
    public User user { get; set; }
    public object geo { get; set; }
    public object coordinates { get; set; }
    public object place { get; set; }
    public object contributors { get; set; }
    public int retweet_count { get; set; }
    public int favorite_count { get; set; }
    public Entities2 entities { get; set; }
    public bool favorited { get; set; }
    public bool retweeted { get; set; }
    public string lang { get; set; }
    public bool? possibly_sensitive { get; set; }
}

public class Tweet
{
    public string UserName { get; set; }
    [JsonProperty(PropertyName = "text")]
    public string Message { get; set; }
    [JsonProperty(PropertyName = "id")]
    public object ID { get; set; }
    [JsonProperty(PropertyName = "created_at")]
    public DateTime TwitTime { get; set; }
}

我尝试用以下方式来反序列化响应:

代码语言:javascript
运行
复制
string str = TwitterAPI(Request.QueryString["screen_name"].ToString(), "10");
var root = JsonConvert.DeserializeObject<List<RootObject>>(str);

其中TwitterAPI()将从以下Twitter API返回响应:

代码语言:javascript
运行
复制
https://api.twitter.com/1.1/statuses/user_timeline.json

下面是详细的错误:

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-07-06 13:40:05

我刚刚找到了答案。

正如文档所说,问题出在Twitter API的局限性上:

“当应用程序超过给定API端点的速率限制时,Twitter API现在将返回HTTP429错误”

我超出了限制,所以它给出了一个异常。

如果达到给定端点的速率限制,这是您将看到的HTTP 429消息的正文:

代码语言:javascript
运行
复制
{
  "errors": [
    {
      "code": 88,
      "message": "Rate limit exceeded"
    }
  ]
}

因此,它只返回JSON格式的错误消息,并将其传递给反序列化函数,反序列化函数将返回该错误。

感谢所有人的建议。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/17488515

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档