user3323180
user3323180

Reputation: 43

Cannot deserialize the current JSON array (e.g. [1,2,3])

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

Upvotes: 0

Views: 4655

Answers (1)

L.B
L.B

Reputation: 116178

It requires an array or a list, try

List<authObject>  list = JsonConvert.DeserializeObject<List<authObject>>(result);

Upvotes: 3

Related Questions