所以我只是有一个简单的 Web API,它返回 JSON 格式如下
{
"dailyDealId": "432",
"discountPercentage": "0",
"product": {
"productId": "10",
"brandId": "10",
"departmentId": "3",
"name": "Baby Girl Velour Tunic & Snowflake Legging Set",
"description": "The pretty set",
"url": "http://whatever.whatever.com/files/whatever.tif"
}
}
我想在我的 C# 控制台代码上获取这些数据
这是我的模型类 Data.cs
class Data
{
public string dailyDealId { get; set; }
public string discountPercentage { get; set; }
public Array product { get; set; }
}
这是我的主要代码
static void Main(string[] args)
{
HttpClient client = new HttpClient();
client.BaseAddress = new Uri("http://whatever.com/");
HttpResponseMessage response = client.GetAsync("product/").Result;
if (response.IsSuccessStatusCode)
{
var products = response.Content.ReadAsAsync<IEnumerable<Data>>().Result;
foreach (var p in products)
{
Console.WriteLine("dailyDealId" + p.dailyDealId);
}
}
}
但它似乎不起作用,我得到 Newtonsoft.Json.JsonSerializationException:无法反序列化当前 JSON 错误,任何帮助将不胜感激
谢谢