c# - Deserialize JSON Array with JSON.NET from URL -


i using json first time , after search in internet found json.net. thought easy use have problem it. every time use code warning:

cannot deserialize current json array (e.g. [1,2,3]) type 'json_web_api.machine' because type requires json object (e.g. {"name":"value"}) deserialize correctly.

this json array url:

[    {       "id": "machinetool 1",       "guid": "not implemented",       "name": "individueller maschinenname",     },     {       "id": "machinetool 2",       "guid": "not implemented",       "name": "individueller maschinenname",     } ] 

and code:

using system; using system.collections.generic; using system.linq; using system.text; using system.threading.tasks; using system.net; using system.runtime.serialization; using newtonsoft.json;  namespace json_web_api { class program {     static void main()     {         string json = new webclient().downloadstring("http://localhost:12084/machines?format=json");         console.writeline(json);          //string json = @"[{"id":"machinetool 1","guid":"not implemented","name":"individueller maschinenname"},{"id":"machinetool 2","guid":"not implemented","name":"individueller maschinenname"}]         //console.writeline(json)";          machine machine = jsonconvert.deserializeobject<machine>(json);         console.writeline(machine.id);          console.read();     } } [datacontract] class machine {     [datamember]     internal string id { get; set; }      [datamember]     internal string guid { get; set; }      [datamember]     internal string name { get; set; } }  } 

convert list of machine

var machine = jsonconvert.deserializeobject<list<machine>>(json); 

to access data run foreach on machine.

foreach(var data in machine )  {       console.writeline(data.id);  }