Консольное приложение поиска - C#

Узнай цену своей работы

Формулировка задачи:

Дали задание по программированию: "Написать консольное приложение поиска музыкальных альбомов исполнителя. При вводе пользователем названия группы, программа должна запрашивать сервер в поисках списка её альбомов. При отсутствии соединения с сервером, список (если он был загружен ранее) должен подгружаться из локального кэша. Допускается использование любого сервера с любым API (рекомендуется сервис iTunes как не требующий авторизации). Для хранения кэша допускается использование любого носителя (файл, любая база данных). Допускается использование любых сторонних библиотек." Но я абсолютно не знаю как это сделать, даже с чего начать. Помогите, пожалуйста!

Решение задачи: «Консольное приложение поиска»

textual
Листинг программы
string json = "{\r\n \"resultCount\":33,\r\n \"results\": [\r\n{\"wrapperType\":\"artist\", \"artistType\":\"Arti" +
    "st\", \"artistName\":\"The Beatles\", \"artistLinkUrl\":\"https://itunes.apple.com/us/ar" +
    "tist/the-beatles/id136975?uo=4\", \"artistId\":136975, \"amgArtistId\":3644, \"primary" +
    "GenreName\":\"Rock\", \"primaryGenreId\":21}, \r\n{\"wrapperType\":\"artist\", \"artistType\"" +
    ":\"Artist\", \"artistName\":\"Beatles Celebration\", \"artistLinkUrl\":\"https://itunes.a" +
    "pple.com/us/artist/beatles-celebration/id369309908?uo=4\", \"artistId\":369309908, " +
    "\"primaryGenreName\":\"Pop\", \"primaryGenreId\":14}, \r\n{\"wrapperType\":\"artist\", \"arti" +
    "stType\":\"Artist\", \"artistName\":\"Blues Beatles\", \"artistLinkUrl\":\"https://itunes." +
    "apple.com/us/artist/blues-beatles/id1177076976?uo=4\", \"artistId\":1177076976, \"pr" +
    "imaryGenreName\":\"Blues\", \"primaryGenreId\":2}, \r\n{\"wrapperType\":\"artist\", \"artist" +
    "Type\":\"Artist\", \"artistName\":\"Bornagen Beatles\", \"artistLinkUrl\":\"https://itunes" +
    ".apple.com/us/artist/bornagen-beatles/id417746653?uo=4\", \"artistId\":417746653, \"" +
    "primaryGenreName\":\"Pop\", \"primaryGenreId\":14}, \r\n{\"wrapperType\":\"artist\", \"artis" +
    "tType\":\"Artist\", \"artistName\":\"The Beatles Symphonic Orchestra\", \"artistLinkUrl\"" +
    ":\"https://itunes.apple.com/us/artist/the-beatles-symphonic-orchestra/id410698389" +
    "?uo=4\", \"artistId\":410698389}, \r\n{\"wrapperType\":\"artist\", \"artistType\":\"Artist\"," +
    " \"artistName\":\"The Platinum Beatles\", \"artistLinkUrl\":\"https://itunes.apple.com/" +
    "us/artist/the-platinum-beatles/id371061808?uo=4\", \"artistId\":371061808, \"primary" +
    "GenreName\":\"Pop\", \"primaryGenreId\":14}, \r\n{\"wrapperType\":\"artist\", \"artistType\":" +
    "\"Artist\", \"artistName\":\"3 Normal Beatles\", \"artistLinkUrl\":\"https://itunes.apple" +
    ".com/us/artist/3-normal-beatles/id269076416?uo=4\", \"artistId\":269076416, \"primar" +
    "yGenreName\":\"Alternative\", \"primaryGenreId\":20}, \r\n{\"wrapperType\":\"artist\", \"art" +
    "istType\":\"Artist\", \"artistName\":\"Songs The Beatles Gave Away\", \"artistLinkUrl\":\"" +
    "https://itunes.apple.com/us/artist/songs-the-beatles-gave-away/id321298056?uo=4\"" +
    ", \"artistId\":321298056, \"primaryGenreName\":\"Rock\", \"primaryGenreId\":21}, \r\n{\"wra" +
    "pperType\":\"artist\", \"artistType\":\"Artist\", \"artistName\":\"#1 Beatles Lovers\", \"ar" +
    "tistLinkUrl\":\"https://itunes.apple.com/us/artist/1-beatles-lovers/id370331152?uo" +
    "=4\", \"artistId\":370331152, \"primaryGenreName\":\"Pop\", \"primaryGenreId\":14}, \r\n{\"w" +
    "rapperType\":\"artist\", \"artistType\":\"Artist\", \"artistName\":\"Savage Young Beatles\"" +
    ", \"artistLinkUrl\":\"https://itunes.apple.com/us/artist/savage-young-beatles/id796" +
    "23511?uo=4\", \"artistId\":79623511, \"amgArtistId\":877930, \"primaryGenreName\":\"Danc" +
    "e\", \"primaryGenreId\":17}, \r\n{\"wrapperType\":\"artist\", \"artistType\":\"Artist\", \"art" +
    "istName\":\"Beatles Revival Band\", \"artistLinkUrl\":\"https://itunes.apple.com/us/ar" +
    "tist/beatles-revival-band/id215066533?uo=4\", \"artistId\":215066533, \"primaryGenre" +
    "Name\":\"Pop\", \"primaryGenreId\":14}, \r\n{\"wrapperType\":\"artist\", \"artistType\":\"Arti" +
    "st\", \"artistName\":\"The Rolling Beatles\", \"artistLinkUrl\":\"https://itunes.apple.c" +
    "om/us/artist/the-rolling-beatles/id439964146?uo=4\", \"artistId\":439964146, \"prima" +
    "ryGenreName\":\"Pop\", \"primaryGenreId\":14}, \r\n{\"wrapperType\":\"artist\", \"artistType" +
    "\":\"Artist\", \"artistName\":\"The Beatles Revival Band & Orchestra\", \"artistLinkUrl\"" +
    ":\"https://itunes.apple.com/us/artist/the-beatles-revival-band-orchestra/id443425" +
    "560?uo=4\", \"artistId\":443425560, \"primaryGenreName\":\"Pop\", \"primaryGenreId\":14}," +
    " \r\n{\"wrapperType\":\"artist\", \"artistType\":\"Artist\", \"artistName\":\"The Beatles Con" +
    "nection\", \"artistLinkUrl\":\"https://itunes.apple.com/us/artist/the-beatles-connec" +
    "tion/id911648932?uo=4\", \"artistId\":911648932, \"primaryGenreName\":\"Britpop\", \"pri" +
    "maryGenreId\":1132}, \r\n{\"wrapperType\":\"artist\", \"artistType\":\"Artist\", \"artistNam" +
    "e\":\"The Philharmonic Beatles Experience\", \"artistLinkUrl\":\"https://itunes.apple." +
    "com/us/artist/the-philharmonic-beatles-experience/id410698395?uo=4\", \"artistId\":" +
    "410698395}, \r\n{\"wrapperType\":\"artist\", \"artistType\":\"Artist\", \"artistName\":\"The " +
    "Savage Young Beatles\", \"artistLinkUrl\":\"https://itunes.apple.com/us/artist/the-s" +
    "avage-young-beatles/id304600324?uo=4\", \"artistId\":304600324, \"amgArtistId\":87793" +
    "0, \"primaryGenreName\":\"Rock\", \"primaryGenreId\":21}, \r\n{\"wrapperType\":\"artist\", \"" +
    "artistType\":\"Artist\", \"artistName\":\"The Bootleg Beatles\", \"artistLinkUrl\":\"https" +
    "://itunes.apple.com/us/artist/the-bootleg-beatles/id165911529?uo=4\", \"artistId\":" +
    "165911529}, \r\n{\"wrapperType\":\"artist\", \"artistType\":\"Software Artist\", \"artistNa" +
    "me\":\"Beat-les Group IKE\", \"artistLinkUrl\":\"https://itunes.apple.com/us/developer" +
    "/beat-les-group-ike/id1195719806?uo=4\", \"artistId\":1195719806}, \r\n{\"wrapperType\"" +
    ":\"artist\", \"artistType\":\"Artist\", \"artistName\":\"The Savage Young Beatles featuri" +
    "ng Tony Sheridan\", \"artistLinkUrl\":\"https://itunes.apple.com/us/artist/the-savag" +
    "e-young-beatles-featuring-tony-sheridan/id288180269?uo=4\", \"artistId\":288180269," +
    " \"primaryGenreName\":\"Rock\", \"primaryGenreId\":21}, \r\n{\"wrapperType\":\"artist\", \"ar" +
    "tistType\":\"Artist\", \"artistName\":\"The Beatles Acoustic Trio\", \"artistLinkUrl\":\"h" +
    "ttps://itunes.apple.com/us/artist/the-beatles-acoustic-trio/id976631872?uo=4\", \"" +
    "artistId\":976631872, \"primaryGenreName\":\"Pop\", \"primaryGenreId\":14}, \r\n{\"wrapper" +
    "Type\":\"artist\", \"artistType\":\"Artist\", \"artistName\":\"The New York Beatles Show\"," +
    " \"artistLinkUrl\":\"https://itunes.apple.com/us/artist/the-new-york-beatles-show/i" +
    "d370546235?uo=4\", \"artistId\":370546235, \"primaryGenreName\":\"Pop\", \"primaryGenreI" +
    "d\":14}, \r\n{\"wrapperType\":\"artist\", \"artistType\":\"Artist\", \"artistName\":\"The Sava" +
    "ge Young Beatles with Tony Sheridan\", \"artistLinkUrl\":\"https://itunes.apple.com/" +
    "us/artist/the-savage-young-beatles-with-tony-sheridan/id984990630?uo=4\", \"artist" +
    "Id\":984990630}, \r\n{\"wrapperType\":\"artist\", \"artistType\":\"Artist\", \"artistName\":\"" +
    "The Ukulele Beatles\", \"artistLinkUrl\":\"https://itunes.apple.com/us/artist/the-uk" +
    "ulele-beatles/id606182486?uo=4\", \"artistId\":606182486, \"primaryGenreName\":\"Pop\"," +
    " \"primaryGenreId\":14}, \r\n{\"wrapperType\":\"artist\", \"artistType\":\"Artist\", \"artist" +
    "Name\":\"#1 Beatles Fantasy Band\", \"artistLinkUrl\":\"https://itunes.apple.com/us/ar" +
    "tist/1-beatles-fantasy-band/id370546167?uo=4\", \"artistId\":370546167}, \r\n{\"wrappe" +
    "rType\":\"artist\", \"artistType\":\"Artist\", \"artistName\":\"Memphis Loves The Beatles " +
    "Studio Band\", \"artistLinkUrl\":\"https://itunes.apple.com/us/artist/memphis-loves-" +
    "the-beatles-studio-band/id673285434?uo=4\", \"artistId\":673285434, \"primaryGenreNa" +
    "me\":\"R&B/Soul\", \"primaryGenreId\":15}, \r\n{\"wrapperType\":\"artist\", \"artistType\":\"A" +
    "rtist\", \"artistName\":\"The Tape-Beatles\", \"artistLinkUrl\":\"https://itunes.apple.c" +
    "om/us/artist/the-tape-beatles/id1165121174?uo=4\", \"artistId\":1165121174, \"primar" +
    "yGenreName\":\"Electronic\", \"primaryGenreId\":7}, \r\n{\"wrapperType\":\"artist\", \"artis" +
    "tType\":\"Artist\", \"artistName\":\"Bootleg Beatles\", \"artistLinkUrl\":\"https://itunes" +
    ".apple.com/us/artist/bootleg-beatles/id370627110?uo=4\", \"artistId\":370627110}, \r" +
    "\n{\"wrapperType\":\"artist\", \"artistType\":\"Artist\", \"artistName\":\"Tampere Beatles H" +
    "appening\", \"artistLinkUrl\":\"https://itunes.apple.com/us/artist/tampere-beatles-h" +
    "appening/id1082950038?uo=4\", \"artistId\":1082950038, \"primaryGenreName\":\"Pop\", \"p" +
    "rimaryGenreId\":14}, \r\n{\"wrapperType\":\"artist\", \"artistType\":\"Artist\", \"artistNam" +
    "e\":\"Japanese Beatles\", \"artistLinkUrl\":\"https://itunes.apple.com/us/artist/japan" +
    "ese-beatles/id453677615?uo=4\", \"artistId\":453677615, \"primaryGenreName\":\"Alterna" +
    "tive\", \"primaryGenreId\":20}, \r\n{\"wrapperType\":\"artist\", \"artistType\":\"Artist\", \"" +
    "artistName\":\"Beatle\'s Wart\", \"artistLinkUrl\":\"https://itunes.apple.com/us/artist" +
    "/beatles-wart/id577701203?uo=4\", \"artistId\":577701203, \"amgArtistId\":2992181, \"p" +
    "rimaryGenreName\":\"Pop\", \"primaryGenreId\":14}, \r\n{\"wrapperType\":\"artist\", \"artist" +
    "Type\":\"Artist\", \"artistName\":\"BPC - Beatles Para CrianГ§as\", \"artistLinkUrl\":\"htt" +
    "ps://itunes.apple.com/us/artist/bpc-beatles-para-crian%C3%A7as/id1134646093?uo=4" +
    "\", \"artistId\":1134646093, \"primaryGenreName\":\"Children\'s Music\", \"primaryGenreId" +
    "\":4}, \r\n{\"wrapperType\":\"artist\", \"artistType\":\"Artist\", \"artistName\":\"The Beatle" +
    "s etcetera\", \"artistLinkUrl\":\"https://itunes.apple.com/us/artist/the-beatles-etc" +
    "etera/id388195904?uo=4\", \"artistId\":388195904, \"primaryGenreName\":\"Spoken Word\"," +
    " \"primaryGenreId\":50000061}, \r\n{\"wrapperType\":\"artist\", \"artistType\":\"Artist\", \"" +
    "artistName\":\"Los Beatles De Cadiz\", \"artistLinkUrl\":\"https://itunes.apple.com/us" +
    "/artist/los-beatles-de-cadiz/id255880236?uo=4\", \"artistId\":255880236, \"primaryGe" +
    "nreName\":\"Pop\", \"primaryGenreId\":14}]\r\n}";
JObject j = JObject.Parse(json);
int resultCount = (int)j["resultCount"];
JArray jArtists = (JArray)j["results"];
for (int i=0; i<resultCount; i++)
{
    string artistName = (string)jArtists[i]["artistName"];
    int artistId = (int)jArtists[i]["artistId"];
    Console.WriteLine("{0}, {1}", artistName, artistId);
}

ИИ поможет Вам:


  • решить любую задачу по программированию
  • объяснить код
  • расставить комментарии в коде
  • и т.д
Попробуйте бесплатно

Оцени полезность:

8   голосов , оценка 4.125 из 5
Похожие ответы