JSON 字符串未使用布尔值和字符串正确反序列化

JSON string not Deserialize properly with boolean and string

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

结果字符串是

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

我已经构建了 class

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

并用代码解析

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

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

我有没有做错什么?

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

将 class 更改为:

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