Employee m = JsonConvert.DeserializeObject<employee>(sc);
Above you're saying that there is only 1 item, not a list of items. Use:
List<Employee> m = JsonConvert.DeserializeObject<List<Employee>>(sc);
UPDATE: Here is a
working example using the answer above:
using Newtonsoft.Json;
string rawJson = @"[ { ""id"" : ""hoho1"",
""pw"" : ""08217"",
""name"" : ""Potter""
},
{ ""id"" : ""hoho2"",
""pw"" : ""1677"",
""name"" : ""Kane""
},
{ ""id"" : ""hoho3"",
""pw"" : ""1541"",
""name"" : ""Moody""
},
{ ""id"" : ""hoho4"",
""pw"" : ""0510"",
""name"" : ""christina""
}
]";
List<Employee> results = JsonConvert.DeserializeObject<List<Employee>>(rawJson);
foreach (var item in results)
Console.WriteLine($"id: {item.id} | pw: {item.pw} | name: {item.name}");
Console.ReadKey();
public class Employee
{
public string id { get; set; }
public string pw { get; set; }
public string name { get; set; }
}
NOTE: The above code is for a .Net 7.0 console app. Same applies to .Net Framework 4.8 and earlier, just needs to be wrapped in a standard console app.
And the output:
id: hoho1 | pw: 08217 | name: Potter
id: hoho2 | pw: 1677 | name: Kane
id: hoho3 | pw: 1541 | name: Moody
id: hoho4 | pw: 0510 | name: christina