【问题标题】:JSON string not Deserialize properly with boolean and stringJSON字符串不能用布尔值和字符串正确反序列化
【发布时间】:2015-09-15 01:26:59
【问题描述】:

我正在尝试解析一个简单的 JSON 响应。

结果字符串是

{"Success":false,"Response":"Error"}

我已经建立了这个类

class JsonResponse
{
  public bool cSuccess { get; set; }
  public string cResponse { get; set; }
}

并用代码解析

JsonResponse message = new JavaScriptSerializer().Deserialize<JsonResponse>(result);

但是,只有 message.cSuccess 填充了 false,而 message.cResponse 仍然为空。

我犯了什么错误吗?

【问题讨论】:

    标签: .net json c#-4.0 javascriptserializer


    【解决方案1】:

    您的类中的属性名称需要与 JSON 字符串中的属性匹配。

    将类更改为:

    class JsonResponse
    {
      public bool Success { get; set; }
      public string Response { get; set; }
    }
    

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-10-20
    • 1970-01-01
    • 2016-12-22
    • 2012-10-21
    • 1970-01-01
    • 2014-08-06
    • 1970-01-01
    • 2021-09-02
    相关资源
    最近更新 更多