我使用的是在线Api Json,但是我收到了这个错误:
Newtonsoft.Json.JsonSerializationException:'转换值" {" Id":82800,"名称":" Pet Cage" ," Level":20," Class":" Battle Pets"," SubClass":" BattlePet",& #34; VendorBuy":0," VendorSell":0,"市场价值":0," MinBuyout":0,"数量&#34 ;:0," NumAuctions":0," HistoricalPrice":0," RegionMarketAvg":0," RegionMinBuyoutAvg":0,&# 34; RegionQuantity":0," RegionHistoricalPrice":38045754," RegionSaleAvg":152352186" RegionAvgDailySold":0," RegionSaleRate" :0," URL":" HTTPS:?//www.tradeskillmaster.com/items/pet-cage-82800境界= EU-拉格纳罗斯"}"输入' System.Collections.Generic.List`1 [TSM.Results]'。路径'',第1行,第495位。'
我想让Api Json(包含数据)显示在列表中。我可以从API获取数据但在我的JSON转换中的某些地方出错了。
我使用以下代码:
HttpClient Connection = new HttpClient();
Connection.BaseAddress = new Uri("http://api.tradeskillmaster.com/v1/item/EU/ragnaros/82800?format=json&apiKey=***hidden***");
Connection.DefaultRequestHeaders.Add("User-Agent", "TSM battle pet");
HttpResponseMessage response = Connection.GetAsync("").Result;
//var emp = response.Content.ReadAsAsync<IEnumerable<Results>>().Result;
var emp = response.Content.ReadAsStringAsync().Result;
var New_Json = emp.Replace("\\\\", "");
string json = JsonConvert.SerializeObject(New_Json);
var parsedObject = JsonConvert.DeserializeObject<JObject>(emp);
foreach (var dataset in parsedObject.Properties())
{
Console.WriteLine(dataset.Name);
}
List<Results> items = JsonConvert.DeserializeObject<List<Results>>(json); // <----- THIS ONE GIVE's THE ERROR
有谁知道如何修复此错误,以便我能正确地将其列入清单?
提前致谢!