1

I'm trying to parse a simple JSON response.

The result string is

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

And I've built the class

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

And parse with the code

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

However only message.cSuccess is populated with false, while message.cResponse is still null.

Is there any mistake I've made?

ydoow
  • 2,969
  • 4
  • 24
  • 40

1 Answers1

1

The names of the properties in your class need to match the properties in the JSON string.

Change the class to be:

class JsonResponse
{
  public bool Success { get; set; }
  public string Response { get; set; }
}
Steve
  • 9,335
  • 10
  • 49
  • 81
  • 1
    Note that you *can* have different names in your class, but without using a library like [Json.Net](http://www.newtonsoft.com/json), it's quite complex. See here: http://stackoverflow.com/questions/1100191/javascriptserializer-deserialize-how-to-change-field-names – Steve Sep 15 '15 at 01:33