我想从API Get Call中获取一个JSON,代码正好在 服务器并成功获取数据,但它给我一些HTML JSON。我只想要json并使用它。 我也从邮递员那里找到了这个链接,但是选择了json,但它给了 我这个: -
意外'<'
我调用api的代码: -
string Baseurl = "http://**********.******.net/";
public async Task<ActionResult> Index()
{
List<Status> EmpInfo = new List<Status>();
using (var client = new HttpClient())
{
client.BaseAddress = new Uri(Baseurl);
client.DefaultRequestHeaders.Clear();
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
HttpResponseMessage Res = await client.GetAsync("Help/Api/GET-api-Test-CheckStatus");
if (Res.IsSuccessStatusCode)
{
var EmpResponse = Res.Content.ReadAsStringAsync().Result;
EmpInfo = JsonConvert.DeserializeObject<List<Status>>(EmpResponse); //Error on this Line
}
return View(EmpInfo);
}
}
当我这样做时,它在这一行上给了我这个错误: -
EmpInfo = JsonConvert.DeserializeObject<List<Status>>(EmpResponse);
,错误是: -
[JsonReaderException:解析值时遇到意外的字符: &LT ;.路径'',第0行,第0位。] Newtonsoft.Json.JsonTextReader.ParseValue()+1097 Newtonsoft.Json.JsonTextReader.Read()+ 103 Newtonsoft.Json.JsonReader.ReadForType(JsonContract contract,Boolean hasConverter)+71 Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize (JsonReader reader,Type objectType,Boolean checkAdditionalContent)+489 Newtonsoft.Json.JsonSerializer.DeserializeInternal(JsonReader reader,Type objectType)+210 Newtonsoft.Json.JsonConvert.DeserializeObject(字符串值,类型类型, JsonSerializerSettings设置)+136 Newtonsoft.Json.JsonConvert.DeserializeObject(String value, JsonSerializerSettings设置)+66 Newtonsoft.Json.JsonConvert.DeserializeObject(String value)+42 ConsumeHttpClient.Controllers.d__1.MoveNext()in System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务任务) 99