我有一个基本上如下的网址:
https://example.com/us/cgi-bin/webscr?cmd=_express-checkout\u0026token=EC-2BF46053LU471230V
URL是通过以下语句生成的:
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);
}
出于某种原因,我的网址包含:
\u0026
即使在使用
之后我也无法摆脱的标志Regex.Unescape()
方法......我甚至尝试过使用
Replace("\u0026","&")
但是那也不起作用......
网址格式应如下:
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);
}
回复仍然包含\ u0026
答案 0 :(得分:1)
您可以使用 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);
答案 1 :(得分:-1)
here use "@" like this
Replace(@"\u0026","$");