C# 无法显示带标签的API响应

C# 无法显示带标签的API响应,c#,asp.net,json,amazon-web-services,serialization,C#,Asp.net,Json,Amazon Web Services,Serialization,我是ASP.NET新手。最近,我创建了自己的api。因此,我决定创建一个web表单来测试api。然而,反应并不明显,我相信我所做的一切都是正确的 我的web表单代码隐藏 using System; using Newtonsoft.Json; using FoodBlog.Model; namespace FoodBlog { public partial class Home : System.Web.UI.Page { protected void Pag

我是ASP.NET新手。最近,我创建了自己的api。因此,我决定创建一个web表单来测试api。然而,反应并不明显,我相信我所做的一切都是正确的

我的web表单代码隐藏

using System;
using Newtonsoft.Json;
using FoodBlog.Model;


namespace FoodBlog
{
    public partial class Home : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            var weatherData = new WeatherData();
            var webClient = new System.Net.WebClient();
            var json = webClient.DownloadString("https://1ibewdli19.execute-api.us-east-2.amazonaws.com/Working/blogid/1");
            string replacedString = json.Replace("<", "");
            string replacedString1 = replacedString.Replace(">", "");
            WeatherData wdata = JsonConvert.DeserializeObject<WeatherData>(replacedString1);

            Label1.Text = wdata.description;
        }
    }
}
JSON数据工作正常(使用Postman)

{
“id”:“,
“图标”:“,
“时间”:”
}

您的JSON字符串与您的
模型不匹配,您可以尝试使用属性映射JSON字符串和模型属性

public class WeatherData
{
    [JsonProperty("id")]
    public string description { get; set; }
    [JsonProperty("icon")]
    public string iconDesc { get; set; }
    [JsonProperty("time")]
    public string TimeStamp { get; set; }
}
或者使用这个类,您将获得JSON数据

public class WeatherData
{
    public string id { get; set; }
    public string icon { get; set; }
    public string time { get; set; }
}

您的JSON字符串无法匹配您的
模型
,您可以尝试使用属性映射JSON字符串和模型属性

public class WeatherData
{
    [JsonProperty("id")]
    public string description { get; set; }
    [JsonProperty("icon")]
    public string iconDesc { get; set; }
    [JsonProperty("time")]
    public string TimeStamp { get; set; }
}
或者使用这个类,您将获得JSON数据

public class WeatherData
{
    public string id { get; set; }
    public string icon { get; set; }
    public string time { get; set; }
}

使用postman,或通过浏览器的开发工具(通常是F12)检查响应/请求。JSON和model不支持match@Nkosi啊哈,谢谢你的提示!使用postman,或通过浏览器的开发工具(通常是F12)检查响应/请求。JSON和model不支持match@Nkosi啊哈,谢谢你的提示!