C# JSON.NET解析Twitter存档问题
我试图用JSON.NET解析包含您所有推文的JSON 基本上我只需要“text”和“id”的值。 这是我目前用于解析它的代码:C# JSON.NET解析Twitter存档问题,c#,json,twitter,C#,Json,Twitter,我试图用JSON.NET解析包含您所有推文的JSON 基本上我只需要“text”和“id”的值。 这是我目前用于解析它的代码: string file = ReadJSON(filename); var parsedFile = JsonConvert.DeserializeObject(file, typeof(ATweet)); 字符串文件基本上是包含当月twitter存档的任何给定.js文件中的所有行。排除第一行,因为第一行总是导致JSON解析失败。 这些是我(尝试)将这些值读入的类:
string file = ReadJSON(filename);
var parsedFile = JsonConvert.DeserializeObject(file, typeof(ATweet));
字符串文件基本上是包含当月twitter存档的任何给定.js文件中的所有行。排除第一行,因为第一行总是导致JSON解析失败。
这些是我(尝试)将这些值读入的类:
[JsonObject]
class ATweet
{
[JsonProperty(PropertyName = "source")]
public string Source { get; set; }
[JsonProperty(PropertyName = "entities")]
public ATweetEntities Entities { get; set; }
[JsonProperty(PropertyName = "geo")]
public string Location { get; set; }
[JsonProperty(PropertyName = "id_str")]
public string IdStr { get; set; }
[JsonProperty(PropertyName = "text")]
public string Text { get; set; }
[JsonProperty(PropertyName = "id")]
public long Id { get; set; }
[JsonProperty(PropertyName = "created_at")]
public string CreationTime { get; set; }
[JsonProperty(PropertyName = "user")]
public ATwitterUser Author { get; set; }
}
[JsonObject]
class ATweetEntities
{
[JsonProperty(PropertyName = "user_mentions")]
public string[] Mentions { get; set; }
[JsonProperty(PropertyName = "media")]
public string[] Media { get; set; }
[JsonProperty(PropertyName = "hashtags")]
public string[] HashTags { get; set; }
[JsonProperty(PropertyName = "urls")]
public string[] Urls { get; set; }
}
class ATwitterUser
{
[JsonProperty(PropertyName = "name")]
public string UserName { get; set; }
[JsonProperty(PropertyName = "screen_name")]
public string ScreenName { get; set; }
[JsonProperty(PropertyName = "protected")]
public bool IsProtected { get; set; }
[JsonProperty(PropertyName = "id_str")]
public string IdStr { get; set; }
[JsonProperty(PropertyName = "profile_image_url_https")]
public string ProfileImageUrl { get; set; }
[JsonProperty(PropertyName = "id")]
public long Id { get; set; }
[JsonProperty(PropertyName = "verified")]
public bool IsVerified { get; set; }
}
但当我尝试运行它时,在JsonConvert.DeserializeObject行中会出现以下异常:
Cannot deserialize the current JSON array (e.g. [1,2,3]) into type 'ThisNamespace.ATweet' because the type requires a JSON object (e.g. {"name":"value"}) to deserialize correctly.
文件中的每个元素都需要是这样的名称-值对
screen_name : value
profile_image_url_https : value