北出 2011-05-09 23:45
浏览 269
已采纳

javascript eval成json出错,太恼火了

这是从后台对出的字符串:
{"300001":{"current":3000.0,"highest":3000.0,"lowest":3000.0,"range":null,"sid":"300001","sname":"上证指数","tody":-1.0,"yesterday":3000.0},"601398":{"current":6.44,"highest":6.44,"lowest":6.44,"range":null,"sid":"601398","sname":"工商银行","tody":-1.0,"yesterday":6.44},"600000":{"current":25.0,"highest":25.0,"lowest":25.0,"range":null,"sid":"600000","sname":"浦发银行","tody":-1.0,"yesterday":25.0},"601857":{"current":1900.0,"highest":1900.0,"lowest":1900.0,"range":null,"sid":"601857","sname":"中国石油","tody":-1.0,"yesterday":1900.0}}

但我直接eval(),这个支付串的时候 firebug 提示invalid label错误, 若是在eval("\""+这个字符串+"\"");提示missing ; before statement 错误,
到底怎样我才能将这个字符串转化为json对象,
请各位给点意见//

  • 写回答

1条回答 默认 最新

  • weixin_42518082 2011-05-09 23:52
    关注

    [color=darkblue][b]需要用括号把字符串括起来..[/b][/color]

    [code="js"]var s = '{"300001":{"current":3000.0,"highest":3000.0,"lowest":3000.0,"range":null,"sid":"300001","sname":"上证指数","tody":-1.0,"yesterday":3000.0},"601398":{"current":6.44,"highest":6.44,"lowest":6.44,"range":null,"sid":"601398","sname":"工商银行","tody":-1.0,"yesterday":6.44},"600000":{"current":25.0,"highest":25.0,"lowest":25.0,"range":null,"sid":"600000","sname":"浦发银行","tody":-1.0,"yesterday":25.0},"601857":{"current":1900.0,"highest":1900.0,"lowest":1900.0,"range":null,"sid":"601857","sname":"中国石油","tody":-1.0,"yesterday":1900.0}} ';
    eval("("+s+")")[/code]

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 高德地图点聚合中Marker的位置无法实时更新
  • ¥15 DIFY API Endpoint 问题。
  • ¥20 sub地址DHCP问题
  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办