我像这样调用谷歌的字典 api:
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"));
但是我得到一个响应,该代码无法正确解析:
json = json.Replace("dict_api.callbacks.id100(", "").Replace(",200,null)", "");
JObject o = JObject.Parse(json);
解析在遇到以下情况时死亡:
"entries":[{"type":"example","terms":[{"type":"text","text":"\x3cem\x3ebars\x3c/em\x3e of sunlight shafting through the broken windows","language":"en"}]}]}
这
\x3cem\x3ebars\x
东西杀死了解析
有没有办法用 JSON.NET 处理这个 JSONP 响应?
aquinas对另一个“Parse JSONP”问题的回答显示了很好的正则表达式来处理 JSONP 部分(可能需要针对这种情况调整正则表达式),所以这里的主要部分是如何处理十六进制编码的字符。x = Regex.Replace(x, @"^.+?\(|\)$", "");