I am currently using Json.Net to deserialize my JSON. I now have the following situation:
I am getting the following JSON response:
{"Success":false,"Errors":{"UserName":"User Name already registered","EmailAddress":"Email Address already registered"}}
I want to parse it into this type:
public class CustomJsonResult
{
public bool Success { get; set; }
public string[] Errors { get; set; }
}
Using Json.net, I tried doing this:
CustomJsonResult regResult = JsonConvert.DeserializeObject<CustomJsonResult>(json);
But this is not working, I get the error Cannot deserialize JSON object into type ‘System.String[]’.
How can I fix this? (using Json.Net or any other library)
The problem is you’re trying to convert a dictionary into an array. Try replacing your
string[]withDictionary<string, string>.