我正在使用自动化测试,并定期看到此错误,该错误未能通过其中一项测试
Newtonsoft.Json.JsonReaderException : Error reading JObject from JsonReader. Path '', line 0, position 0.
TearDown : Newtonsoft.Json.JsonReaderException : Error reading JObject from JsonReader. Path '', line 0, position 0.
at Newtonsoft.Json.Linq.JObject.Load(JsonReader reader, JsonLoadSettings settings)
at Newtonsoft.Json.Linq.JObject.Parse(String json, JsonLoadSettings settings)
at Project.Command.User.WebApi.SessionWebApiData.UpdateUserAndDealer()
at Project.FuncTests.Rock.ROCKTests.TestUserCanDownloadApprovedHtmlBannerTransaction() in <path>\ROCKTests.cs:line 652
--TearDown
at Newtonsoft.Json.Linq.JObject.Load(JsonReader reader, JsonLoadSettings settings)
at Newtonsoft.Json.Linq.JObject.Parse(String json, JsonLoadSettings settings)
at Project.Command.User.WebApi.SessionWebApiData.UpdateUserAndDealer()
at Project.FuncTests.Base.TestSetup.TearDown() in <Path>\Base\TestSetup.cs:line 139
我不明白为什么它有时会起作用 我是Newtonsoft.Json的最新版本
有代码:
internal static void UpdateUserAndDealer()
{
var sessionDealerAndUserJson = AjaxRequest.Create("GET", $"{Support.BaseUrl}WebAPI/api/Retailer/GetSessionDealerAndUser");
sessionDealerAndUserJson.Send();
var dealerAndUserJO = JObject.Parse(sessionDealerAndUserJson.Response);
//var dealerAndUserJO = JsonConvert.DeserializeObject(sessionDealerAndUserJson.Response);
Dealer = dealerAndUserJO["DealerInfo"].ToObject<DealerDto>();
User = dealerAndUserJO["UserInfo"].ToObject<UserDto>();
var cultureJson = AjaxRequest.Create("GET", $"{Support.BaseUrl}WebAPI/api/culture");
cultureJson.Send();
Cultures = JsonConvert.DeserializeObject<List<CultureDto>>(cultureJson.Response);
Currency = Cultures.Find(x => x.Name.Equals(User.CultureName)).CurrencySymbol;
}