Skip to content

Instantly share code, notes, and snippets.

@shmutalov
Last active December 13, 2020 11:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shmutalov/4ca3f259b93aaabee4f09079f5b8d60a to your computer and use it in GitHub Desktop.
Save shmutalov/4ca3f259b93aaabee4f09079f5b8d60a to your computer and use it in GitHub Desktop.
Console.OutputEncoding = Encoding.UTF8;
var data = File.ReadAllText("raw.txt");
data = data.Substring(1, data.Length - 3);
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine(data);
//replace escaped Unicode characters, see \u0026 => &
data = Regex.Replace(data, @"\\u([0-9A-F]{4})", match => ((char)int.Parse(match.Groups[1].Value, NumberStyles.HexNumber)).ToString(), RegexOptions.IgnoreCase);
//now replace escaped ASCII character, see \x32 => 2
data = Regex.Replace(data, @"\\x([0-9A-F]{2})", match => ((char)int.Parse(match.Groups[1].Value, NumberStyles.HexNumber)).ToString(), RegexOptions.IgnoreCase);
//then unescape escaped characters (LOL WUT???) see => \& ==> &
data = Regex.Replace(data, @"\\(.)", match => match.Groups[1].Value, RegexOptions.IgnoreCase);
//replace HTML-escaped Unicode characters, see %U0026 => &
data = Regex.Replace(data, @"%U([0-9A-F]{4})", match => ((char)int.Parse(match.Groups[1].Value, NumberStyles.HexNumber)).ToString(), RegexOptions.IgnoreCase);
//now replace HTML-escaped ASCII character, see %32 => 2
data = Regex.Replace(data, @"%([0-9A-F]{2})", match => ((char)int.Parse(match.Groups[1].Value, NumberStyles.HexNumber)).ToString(), RegexOptions.IgnoreCase);
Console.ForegroundColor = ConsoleColor.Yellow;
Console.WriteLine(data);
dynamic json = JObject.Parse(data);
Console.ForegroundColor = ConsoleColor.Blue;
Console.WriteLine(json.contents.singleColumnBrowseResultsRenderer.tabs);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment