【发布时间】:2015-10-31 19:09:20
【问题描述】:
我有一个这样的字符串,它是从数据库中检索的。我需要将字符串转换为 Javascript 字典。
"['content':{'type':'file','path':'callie/circle'},'video':{'videoId':'CvIr-2lMLsk','startSeconds': 15,'endSeconds': 30'}]".
如何将上述字符串转换为 Javascript 字典?我应该先将字符串转换为json吗?当我尝试json.parse 时,显示错误:
Uncaught SyntaxError: Unexpected token '
在 Object.parse(本机)
在:2:6
在 Object.InjectedScript._evaluateOn (:905:140)
在 Object.InjectedScript._evaluateAndWrap (:838:34)
在 Object.InjectedScript.evaluate (:694:21)
【问题讨论】:
-
您尝试过使用地图吗?
-
我怎样才能使用地图呢?我不知道
-
那不是 JSON。字符串需要用双引号,而不是单引号。
-
有效的 json 字符串为:{"content":{"path":"callie/circle","type":"file"},"video":{"videoId":"CvIr- 2lMLsk","endSeconds":"30'","startSeconds":15}} 我建议你先创建正确的json字符串。
标签: javascript json dictionary