我试图从一个超级巨大的JSON文件抢鸣叫......我想要被命名为一“文”反序列化JSON数组作为列表
JSON文件是这样的:
[{"text":"A nice cup of #coffee can speed your day up, and so can Firefox.", "text":"test1",
"text":"test2"}]
编辑:它只抓取最后的文本..“text2”..为什么它不抓取所有的列表?
public class JSONClasses
{
public class SingleTweet
{
[JsonProperty("text")]
public string text { get; set; }
}
}
public class JSONFunctions
{
//public static JSONRoot jsonFile = new JSONRoot();
public static List<JSONClasses.SingleTweet> TweetList = new List<JSONClasses.SingleTweet>();
public static bool Deserialize(string path)
{
try
{
var filePath = File.OpenText(path);
TweetList = JsonConvert.DeserializeObject<List<JSONClasses.SingleTweet>>(filePath.ReadToEnd());
filePath.Close();
return true;
}
catch (Exception)
{
Console.WriteLine("Could not Deserialize: " + path);
return false;
}
}
}
//test to see if it works:
JSONFunctions.Deserialize(AppOptions.JSONTwitterFilePath);
foreach (JSONClasses.SingleTweet temp in JSONFunctions.TweetList)
Console.WriteLine(temp);
请重新打开..我固定它... – user1189352
你没有真正解决任何东西。如果有的话,你的更新使你的问题无效。反序列化您最初发布的JSON工作正常......如果您希望我们能够为您提供帮助,您需要发布_full_例外消息。 –
....你得到的结果是什么? – iandotkelly