评估和非英语字符冲突? [英] eval and non-English characters conflict?

查看:29
本文介绍了评估和非英语字符冲突?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是的,eval是魔鬼的工具,我会燃烧使用它。但是,

在这个例子中它非常方便而且我很懒。


所以,这里有一个奇怪的,我我想知道是否有人有解决方法。

我通过AJAX将数据从服务器中提取出来,其中一些数据中包含了非b / b
非英文字符。数据采用json的形式:


{" exitCode":1," className":" clientRecords"

," strAccountId":" 100"

," strName":" Dr。 Gary A. Martin

,intReportsPurchased:100

,intReportsUsed:13

,intBalance:87

,clientData:{

" r19":{

" className":" client"

," intId":353

," strFname":" NameOf"

," strLname":" Someone"

," strMname":""

}

," r7":{

" className" ;:client

,intId:251

,strFname":BananaHead

," strLname":" Myrb?"

," strMname":""

}

}


对于测试,我使用的是eval(json =" + response.text)。对于任何不具有非英文字符的记录,这是有效的。

然而,当它有像Myrb?这样的东西时

结尾的滑稽o,它会死掉并抛出一个错误对话框,上面写着预期''}''。为什么

它会扼杀有趣的角色?如果我将json

直接复制并粘贴到代码中,它可以正常工作;它只是当它被嵌入

时它会变得越来越好。


为了额外的陌生感,这不会发生在IE5上.5,IE7,FF1.5.x或

FF1.0.x - 仅适用于IE 6 SP2!


有没有人见过这样的? ??


泰勒

Yes, eval is a tool of the devil and I''ll burn for using it. However,
in this instance it''s quite handy and I''m quite lazy.

So, here''s a weird one, and I''m wondering if anyone has a workaround.
I am pulling data off a server via AJAX, and some of that data has
non-English characters in it. The data is in the form of a json:

{"exitCode":1,"className":"clientRecords"
,"strAccountId":"100"
,"strName":"Dr. Gary A. Martin"
,"intReportsPurchased":100
,"intReportsUsed":13
,"intBalance":87
,"clientData":{
"r19":{
"className":"client"
,"intId":353
,"strFname":"NameOf"
,"strLname":"Someone"
,"strMname":""
}
,"r7":{
"className":"client"
,"intId":251
,"strFname":"BananaHead"
,"strLname":"Myrb?"
,"strMname":""
}
}

For testing, I was using eval("json =" +response.text). This works
fine for any records that DON''T have a non-English character in them.
However, when it has something like ''Myrb?'' with the funny o on the
end, it dies and throws an error dialog saying "Expected ''}''". Why
would it choke on the funny character? If I copy and paste the json
directly into the code, it works fine; it''s just when it''s embedded in
the eval that it goes tits up.

For extra strangeness, this does NOT happen on IE5.5, IE7, FF1.5.x or
FF1.0.x - just on IE 6 SP2!

Has anyone ever seen suchlike before???

Tyler

推荐答案

Logos写道:
Logos wrote:

所以,这里有一个奇怪的,我想知道是否有人有解决方法。

我通过AJAX从服务器上提取数据,还有一些该数据中包含

非英文字符。
So, here''s a weird one, and I''m wondering if anyone has a workaround.
I am pulling data off a server via AJAX, and some of that data has
non-English characters in it.


为了更加奇怪,这不会发生在IE5.5,IE7,FF1.5.x或

FF1上.0.x - 仅适用于IE 6 SP2!
For extra strangeness, this does NOT happen on IE5.5, IE7, FF1.5.x or
FF1.0.x - just on IE 6 SP2!



从服务器发送数据时如何编码数据?尝试发送

UTF-8编码数据。虽然它有点奇怪,它适用于IE

5.5和IE 7但不适用于IE 6.


-


Martin Honnen
http://JavaScript.FAQTs.com/


从服务器发送数据时如何编码数据?尝试发送
How is the data encoded when you send it from the server? Try sending

UTF-8编码数据。虽然它有点奇怪,它适用于IE

5.5和IE 7但不适用于IE 6.
UTF-8 encoded data. Although it is somehow strange that it works with IE
5.5 and IE 7 but not with IE 6.



它是直接的ASCII从服务器上的文件。不幸的是我们的

选择后端不允许任何其他编码。真正奇怪的是,我把它复制并直接粘贴到我的代码中,然后它就可以了。

有效;将完全相同的代码段复制并粘贴到我的代码中,但在

eval内,并且它会发生爆炸。奇怪的o字符将其绊倒。来吧,

在IE中尝试一下,它很好看。


It''s straight ASCII from a file on the server. Unfortunately our
choice of back ends doesn''t allow any other encoding. The truly weird
thing is is that I copy and paste it directly into my code, and it
works; copy and paste the exact same snippet into my code but inside an
eval, and it bombs. The odd ''o'' character trips it up. Go ahead and
try it in IE, it''s neat to watch.


" Logos" < ty ********* @ gmail.comwrote in news:1162912848.664818.170200

@ m73g2000cwd.googlegroups.com:
"Logos" <ty*********@gmail.comwrote in news:1162912848.664818.170200
@m73g2000cwd.googlegroups.com:

为了测试,我使用了eval(json =" + response.text)。
For testing, I was using eval("json =" +response.text).



尝试eval(''" json =" + response.text''),看看是否有所作为。

Try eval(''"json =" +response.text'') and see if that makes a difference.


这篇关于评估和非英语字符冲突?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆