Antoine Antoine - 6 months ago 22
JSON Question

Strange JSON Deserialization c#

I'm having troubles with some Deserialization because I'm not receiving an object like I'm used to but an array. Lets to the code, how I've being doing it:

JSON received:

[{"gcm_regID":"fsdf2156fw62f1wfwe512g"}]


Deserialization

var result = JsonConvert.DeserializeObject<Gcm>(response);


Handlers Tried:

public class Gcm
{
public List<Gcm_reg> gcm_regID { get; set; }
}
public class Gcm_reg
{
public string gcm_regID { get; set; }
}


I've tried just the Gcm_reg as well and nothing seems to work. How can I deserialize this? By the way, I'm using the newsoft JSON.

Best regards,

Answer
 IEnumerable<Gcm_reg> result =  JsonConvert.DeserializeObject<IEnumerable<Gcm_reg>>(response);

You can deserialize the object as an array or IEnumerable

Comments