【发布时间】:2012-01-17 17:16:01
【问题描述】:
当我尝试从 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);
}
【问题讨论】:
-
你能告诉我们你的JSON字符串吗?
-
我已经编辑了我的问题以显示 JSON 字符串
-
在哪里?我在您的代码中看不到井号。
-
@BiffBaffBoff 你还没有向我们展示 JSON 字符串,你所做的只是展示生成它的代码,请让我们有发送的确切 JSON,例如使用fiddler,在提取数据时不要使用
eval(),你可以使用var result = $.parseJSON(data);,但不能使用eval() -
嗨,谢谢,我通过不使用 eval() 解决了它;