how can i parse this json response and create c# object
{"Response":"valid","Files":{"0":{"FileURL":"htp:\/\/somedomain.com\/1.exe","FileVersion":1},"1":{"FileURL":"htp:\/\/somedomain.com\/1.exe","FileVersion":2}}}
i have c# class
public class Files
{
public string fileURL;
public string fileVersion;
}
WebClient wc=new WebClient();
string code=wc.DownloadString("http://somedomain.com/GetLatestFiles.php");
List<Files> f=ParseJson(code);
how can i parse this json please help. I need to implement ParseJson which will return files list or can i deserialize this response to c# class?
Thankyou
Edit implemented some solution but its very slow?
public class LatestFile
{
public string fileURL;
public string fileVersion;
}
private List<LatestFile> ParseJson(string code)
{
List<LatestFile> files = new List<LatestFile>();
dynamic jObj = JsonConvert.DeserializeObject(code);
foreach (var child in jObj.Files.Children())
{
string index = child.Name;
string url = child.First.FileURL.Value;
string version = child.First.FileVersion.Value.ToString();
LatestFile f = new LatestFile();
f.fileURL = url;
f.fileVersion = version;
files.Add(f);
}
return files;
}
Based on @Brian Rogers answer below i am able to implement the generic solution working fast and efficiently.Thanks
