开发者

javascript eval json with base64 encoded field

I am using sun.misc.BASE64Encoder to encode an encrypted value, which is then added to a JSON field and subsequently sent to the client. I use Javascript's eval() function on the client to create an object from the JSON code. When eval() runs, it gives the error:

unterminated string literal

There are other fields in the JSON code, but I've narrowed the error specifically to the base64 encoded field. Here's the offending line of ja开发者_StackOverflow社区vascript code:

var result = eval( '(' + xhr.responseText + ')' ); 

Here's the JSON object from the Servlet:

{
  'resource':'resource?Signature=j79r/2Hly+HqhS/6fdd+prfsR+kUNijUvDN0QJ14ZR43gzYScOMDypt/crks/CEphTUXVptJvSol
1ZOOvScCUhNOCb7dZk/3MKnI5tOewSACXK32/OJNd8hYpZtSTn+WhA6+f9BUIUZWA83U8Cud/Tb8V
R1yQWbDGG/mM/NiUSiY=', 

'url':'http://somesite.com/pr'
}

I'm not sure why eval is dying, but it seems the value of the 'resource' JSON field contains something it doesn't care for.

Thanks in advance. Tim


I think it may be because your JSON appears to have line breaks in it. If you remove them, does it work?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜