我有一个URL,基本上如下所示:
https://example.com/us/cgi-bin/webscr?cmd=_express-checkout\u0026token=EC-2BF46053LU471230VURL是从如下语句生成的:
if ((int)response.StatusCode == 200 || (int)response.StatusCode == 201)
{
var res = await content.ReadAsStringAsync();
var url = HttpUtility.HtmlDecode(JsonConvert.DeserializeObject<PayPalBlueReference>(res).paypalTransaction.paypalUrl);
return Json(Regex.Unescape(url), JsonRequestBehavior.AllowGet);
}出于某种原因,我的URL包含以下内容:
\u0026即使在使用之后我也无法摆脱的
Regex.Unescape()方法..。我甚至试过用
Replace("\u0026","&") 但这也没用..。
URL的格式应该如下:
https://example.com/us/cgi-bin/webscr?cmd=_express-checkout&token=EC-2BF46053LU471230V有人能帮我吗?
编辑:服务器返回的JSON如下所示:
"https://example.com/us/cgi-bin/webscr?cmd=_express-checkout\u0026token=EC-2BF46053LU471230V"Edit2:这是使用rokkerboci的方法:
if ((int)response.StatusCode == 200 || (int)response.StatusCode == 201)
{
var res = await content.ReadAsStringAsync();
var url = HttpUtility.HtmlDecode(JsonConvert.DeserializeObject<PayPalBlueReference>(res).paypalTransaction.paypalUrl);
return Json(url.Replace("\\u0026", "&"), JsonRequestBehavior.AllowGet);
}响应仍然包含\u 0026
发布于 2018-01-15 17:54:11
您可以使用System.Web命名空间执行此操作:
string encoded = "https://example.com/us/cgi-bin/webscr?cmd=_express-checkout\u0026token=EC-2BF46053LU471230V";
var unencoded = HttpUtility.HtmlDecode(encoded);
Console.WriteLine(unencoded);https://stackoverflow.com/questions/48268190
复制相似问题