当我尝试从JSON调用中返回一个英镑符号时,在chrome中会出现错误:Uncaught SyntaxError: Unexpected token ILLEGAL
var currency = "";
var price = "";
$.ajax({
type: 'GET',
url: '../JSONDeliveryPrice/',
dataType: 'json',
success: function (data) {
price = eval(data.price);
currency = eval(data.currency);
},
async: false
});
console.log(price);
console.log(currency);
货币应该等于“£”,但我得到了那个错误。我需要以某种方式编码/解码值吗?如果我仅返回价格,则价格输出正确。
编辑:
public virtual ActionResult JSONDeliveryPrice()
{
string currency = "£";
decimal price = 123;
return Json(new { price = price, currency = currency }, JsonRequestBehavior.AllowGet);
}
eval()
,可以使用var result = $.parseJSON(data);
,但绝对不能使用eval()
。 - balexandre