我从未使用过JSON文件,但是我有一个任务需要实现JSON文件并将其转换为IEnumerable。当我尝试反序列化JSON对象时,我会收到一个异常,其中说:
Newtonsoft.Json.JsonSerializationException类型的未处理异常发生在 Newtonsoft.Json.dll 中
其他信息:无法将当前JSON对象(例如{"name":"value"})反序列化为类型“Price_Algorithm.AuctionInfo”,因为该类型需要JSON数组(例如[1,2,3])才能正确反序列化。
我的代码:
var data = File.ReadAllText(@"C:\benatia.json");
var terry = JsonConvert.DeserializeObject<IEnumerable<AuctionInfo>>(data);
public class AuctionInfo : IEnumerable
{
public string BidState { get; set; }
public uint BuyNowPrice { get; set; }
public uint CurrentBid { get; set; }
public int Expires { get; set; }
public ItemData ItemData { get; set; }
public uint StartingBid { get; set; }
public string TradeState { get; set; }
public IEnumerator GetEnumerator()
{
throw new NotImplementedException();
}
}
我已经上传了JSON对象,以便每个人都知道整个JSON文件的内容:http://puu.sh/fancH/9a495ecbe9.json (新的JSON)
AuctionInfo
代码以及它所引用的任何其他自定义类型。 - Timothy Shields