0

我在解析 twitter 流时遇到问题,此代码返回此错误消息:

没有为“System.Collections.Generic.IEnumerable`1[[Xxxx.Website.Templates.WidgetViews.Tweet, Dolphin, Version=1.0.4801.24288, Culture=neutral, PublicKeyToken=null]]”类型定义无参数构造函数。

非常感谢您的帮助!

public partial class TwitterWidgetView
{
  protected override void OnLoad(System.EventArgs e)
  {
    string listName = "sas";
    string twitterListPath = "https://search.twitter.com/search.json?q=" + listName;
    WebClient wc = new WebClient();
    var json = wc.DownloadString(twitterListPath);
    JavaScriptSerializer ser = new JavaScriptSerializer();
    var tweetList = ser.Deserialize<IEnumerable<Tweet>>(json);
  }
}

public class Metadata
    {
        public string result_type { get; set; }
    }


    public class Tweet 
    {
        public Tweet()
        {}

        public string created_at { get; set; }


        public string from_user { get; set; }


        public int from_user_id { get; set; }


        public string from_user_id_str { get; set; }


        public string from_user_name { get; set; }


        public object geo { get; set; }


        public object id { get; set; }

        public string id_str { get; set; }


        public string iso_language_code { get; set; }


        public Metadata metadata { get; set; }


        public string profile_image_url { get; set; }


        public string profile_image_url_https { get; set; }


        public string source { get; set; }

        public string text { get; set; }


        public string to_user { get; set; }


        public int to_user_id { get; set; }


        public string to_user_id_str { get; set; }

        public string to_user_name { get; set; }


        public long? in_reply_to_status_id { get; set; }


        public string in_reply_to_status_id_str { get; set; }


    }

    public class RootObject
    {
        public RootObject()
        {}

        public double completed_in { get; set; }


        public long max_id { get; set; }


        public string max_id_str { get; set; }

        public string next_page { get; set; }


        public int page { get; set; }


        public string query { get; set; }


        public string refresh_url { get; set; }


        public List<Tweet> results { get; set; }


        public int results_per_page { get; set; }


        public int since_id { get; set; }


        public string since_id_str { get; set; }
    }
4

1 回答 1

2

尝试改用列表

var tweetList = ser.Deserialize<List<Tweet>>(json);
于 2013-02-22T13:13:12.503 回答