Get json array from Web api into c# Get json array from Web api into c# json json

Get json array from Web api into c#


As the error suggests,

You are deserializing an array into a class. It will never work. You need to deserialize it into either an array or a list using the below code snippet.

Try:
var data = JsonConvert.DeserializeObject<List<Class2>>(response);
or
var data = JsonConvert.DeserializeObject<Class2[]>(response);
and it will work fine.

EDIT 1:

foreach(var room in data){   string id = room.id;   string name = room.name;   // and so on}


multiple Class2 objects must be use List or Array type to convert them,you can try JsonConvert.DeserializeObject<List<Class2>>(response)