public static XmlToJson ( string xml ) : string | ||
xml | string | |
Résultat | string |
//ユーザーIDからユーザーネームを取得する public static string LookupUserName(string userId) { string uri = UserLookUpURL + userId; string json = NicoNicoUtil.XmlToJson(NicoNicoWrapperMain.GetSession().GetAsync(uri).Result); return(DynamicJson.Parse(json).response.user.nickname); }
//ストーリーボードのデータを取得する private NicoNicoStoryBoardData GetStoryBoardInternalData() { try { var result = NicoNicoWrapperMain.Session.GetResponseAsync(StoryBoardApiBaseUrl + "&sb=1").Result; //見つからなかったり見せてもらえなかったりしたら if (result.StatusCode == HttpStatusCode.Forbidden || result.StatusCode == HttpStatusCode.NotFound || result.Content.Headers.ContentDisposition.FileName.Contains("smile")) { return(null); } byte[] response = result.Content.ReadAsByteArrayAsync().Result; var xml = new string(Encoding.ASCII.GetChars(response)); xml = xml.Substring(39); var json = NicoNicoUtil.XmlToJson(xml); json = json.Replace("@", ""); var root = DynamicJson.Parse(json); if (root.smile.storyboard.IsArray) { foreach (var entry in root.smile.storyboard) { return(new NicoNicoStoryBoardData() { Id = entry.id() ? entry.id : "1", Cols = int.Parse(entry.board_cols), Rows = int.Parse(entry.board_rows), Count = int.Parse(entry.board_number), Width = int.Parse(entry.thumbnail_width), Height = int.Parse(entry.thumbnail_height), Interval = int.Parse(entry.thumbnail_interval), Number = int.Parse(entry.thumbnail_number) }); } } else { var entry = root.smile.storyboard; return(new NicoNicoStoryBoardData() { Id = entry.id() ? entry.id : "1", Cols = int.Parse(entry.board_cols), Rows = int.Parse(entry.board_rows), Count = int.Parse(entry.board_number), Width = int.Parse(entry.thumbnail_width), Height = int.Parse(entry.thumbnail_height), Interval = int.Parse(entry.thumbnail_interval), Number = int.Parse(entry.thumbnail_number) }); } } catch (RequestTimeout) { } return(null); }