I make a call to google's dictionary api like this:
var json = new WebClient().DownloadString(string.Format(@"http://www.google.com/dictionary/json?callback=dict_api.callbacks.id100&q={0}&sl=en&tl=en", "bar"));
However I get a response that this code fails to parse correctly:
json = json.Replace("dict_api.callbacks.id100(", "").Replace(",200,null)", "");
JObject o = JObject.Parse(json);
The parse dies at encountering this:
"entries":[{"type":"example","terms":[{"type":"text","text":"x3cemx3ebarsx3c/emx3e of sunlight shafting through the broken windows","language":"en"}]}]}
The
x3cemx3ebarsx
stuff kills the parse
Is there some way to handle this JSONP response with JSON.NET?
The answer by aquinas to another "Parse JSONP" question shows nice regex x = Regex.Replace(x, @"^.+?(|)$", "");
to handle with JSONP part (may need to tweak regex for this case), so main part here is how to deal with hex-encoded characters.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…