C#
27
Вклад в тег
internal static class Serializer
{
internal static void Serialize<T>(this T arg, string fileName)
{
string res = JsonConvert.SerializeObject(arg, Formatting.Indented);
File.WriteAllText(fileName,res);
}
internal static T Deserialize<T>(string fileName)
{
string json = File.ReadAllText(fileName);
T res = JsonConvert.DeserializeObject<T>(json);
return res;
}
}
public class Item
{
...
public string title{get; set;}
public string url{get;set;}
...
}
public class Response
{
public int count{get;set;}
public List<Item> items{get; set;}
}
string pathToFIle = @"C:\temp\anyFile";
Response response = Serializer.Deserialize<Response>(pathToFile);
String[] titles = response.items.Select(item => item.title).ToArray(); // Массив названий
String[] urls = response.items.Select(item => item.url)ToArray(); // Массив адресов