json to entity in api

时间:2022-04-26 00:58:34

using (var client = new HttpClient())
{
var WVMId = DB.Vehicles.Where(v => v.Id == new Guid(vehicleId)).Select(v => v.WVMID).FirstOrDefault();
var reqUrl = baseUrl + url;
var respurl = string.Format(reqUrl, WVMId);
var response = client.GetStringAsync(respurl).Result;
var json = JArray.Parse(response);
foreach (var temp in json)
{
var model = temp.ToObject(typeof(VehicleMaintenanceItemData), new Newtonsoft.Json.JsonSerializer()) as VehicleMaintenanceItemData;
maintenanceItems.Add(model);
}
return maintenanceItems;
}