问题
i've this error: Cannot deserialize the current JSON array (e.g. [1,2,3]) into type 'authObject' because the type requires a JSON object (e.g. {"name":"value"}) to deserialize correctly.
To fix this error either change the JSON to a JSON object (e.g. {"name":"value"}) or change the deserialized type to an array or a type that implements a collection interface (e.g. ICollection, IList) like List that can be deserialized from a JSON array. JsonArrayAttribute can also be added to the type to force it to deserialize from a JSON array.
my deserialize code
authObject a = JsonConvert.DeserializeObject<authObject>(result);
my class with json object description:
public class authObject
{
public string auth { get; set; }
public string type { get; set; }
public string sess_id { get; set; }
}
Ofcourse my json :
[{"auth":"49","type":"P","sess_id":"89a0d5gle5vspo0ed3j8tbdos4"}]
what i have been done wrongly ? Thanks
回答1:
It requires an array or a list, try
List<authObject> list = JsonConvert.DeserializeObject<List<authObject>>(result);
来源:https://stackoverflow.com/questions/22768013/cannot-deserialize-the-current-json-array-e-g-1-2-3