{
"response":{
"count":198,
"items":[
{
"id":340125039,
"owner_id":34254853,
"artist":"IOWA",
"title":"Маршрутка",
"duration":190,
"url":"http:\/\/cs7-5v4.vk-cdn.net\/p12\/630de313d73392.mp3?extra=fNremCtKgl4pnCbyZ0q-LOBIfvRoUf5QGo8oWwYrOCza6AlSUOdYIImUideFd3hpPa325ckSD_c3zQ5FNluMS80lrSJiM6FC",
"genre_id":9
},
{
"id":340120602,
"owner_id":34254853,
"artist":"Stromae",
"title":"Tous Les Memes",
"duration":168,
"url":"http:\/\/cs7-1v4.vk-cdn.net\/p18\/600b1a66ef64d6.mp3?extra=GNP79R4nHR39dY50YJ_ddDxEuX6SQcxtG3nCgzI0LdvxoaLh5lQ2qZqqpABCqPoXOISyNzWOqMZx4_nTL3bQ31i57z-UXl4V",
"lyrics_id":99395752
}
]
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Newtonsoft.Json;
namespace WpfApplication9
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
Data data = JsonConvert.DeserializeObject<Data>(json);
foreach (Item item in data.Response.Items)
{
listBox1.Items.Add(new ListBoxItem() { Content = item });
}
}
class Data
{
public Response Response;
}
class Response
{
public int Count;
public Item[] Items;
}
class Item
{
public int Id;
public int Owner_id;
public string Artist;
public string Title;
public int Duration;
public string Url;
public int Genre_id;
public override string ToString()
{
return string.Format("{0} ({1})", Title, Url);
}
}
string json = @"{
""response"":{
""count"":198,
""items"":[
{
""id"":340125039,
""owner_id"":34254853,
""artist"":""IOWA"",
""title"":""Маршрутка"",
""duration"":190,
""url"":""http:\/\/cs7-5v4.vk-cdn.net\/p12\/630de313d73392.mp3?extra=fNremCtKgl4pnCbyZ0q-LOBIfvRoUf5QGo8oWwYrOCza6AlSUOdYIImUideFd3hpPa325ckSD_c3zQ5FNluMS80lrSJiM6FC"",
""genre_id"":9
},
{
""id"":340120602,
""owner_id"":34254853,
""artist"":""Stromae"",
""title"":""Tous Les Memes"",
""duration"":168,
""url"":""http:\/\/cs7-1v4.vk-cdn.net\/p18\/600b1a66ef64d6.mp3?extra=GNP79R4nHR39dY50YJ_ddDxEuX6SQcxtG3nCgzI0LdvxoaLh5lQ2qZqqpABCqPoXOISyNzWOqMZx4_nTL3bQ31i57z-UXl4V"",
""lyrics_id"":99395752
}
]
}
}";
}
}
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(); // Массив адресов