获取到了网页中script
里面的文本,是一个JSON
对象,但是使用JSON.parse
解析的话会报错。使用eval
可以解析数据,但是这样是否不太安全。有什么比较好的方法吗?谢谢!
16 回复
a = $('script:contains("songs")').text()
"
songs = [
{
index : "1",
title : "此时此刻",
hot : "22026",
url: "/share/songRedict.do?id=4616853720955750635&source=0&token=c0fd73993e93ca35ff337538a5584c1f"
}
,
{
index : "2",
title : "爱情",
hot : "18526",
url: "/share/songRedict.do?id=4616853720955750636&source=0&token=659fff03d7dffa3d0f3bba5441c7c9fd"
}
,
{
index : "3",
title : "逍遥行",
hot : "18533",
url: "/share/songRedict.do?id=4616853720955750637&source=0&token=e567ffbf67dd6452c2d30f1df1229e04"
}
,
{
index : "4",
title : "灵岩",
hot : "6875",
url: "/share/songRedict.do?id=4616853720955750638&source=0&token=4f982339445e2597a2db00d9fb7be2e5"
}
,
{
index : "5",
title : "空谷幽兰",
hot : "47523",
url: "/share/songRedict.do?id=4616853720955750639&source=0&token=a659ed0256888209559b4592041d1e58"
}
,
{
index : "6",
title : "出离",
hot : "3961",
url: "/share/songRedict.do?id=4616853720955750640&source=0&token=5c47470f6b5be9217658a5cc0b08d296"
}
,
{
index : "7",
title : "喜悦",
hot : "25604",
url: "/share/songRedict.do?id=4616853720955750641&source=0&token=8af31680e95dc1e80c1e118781bdbe56"
}
,
{
index : "8",
title : "心愿",
hot : "4971",
url: "/share/songRedict.do?id=4616853720955750642&source=0&token=583b08ea26f3e2fbcb09ed1516508c94"
}
,
{
index : "9",
title : "救赎之旅",
hot : "16890",
url: "/share/songRedict.do?id=4616853720955750643&source=0&token=f9b10c720f70f4cb6a5ecfa9dae3bd30"
}
,
{
index : "10",
title : "世外桃源",
hot : "23628",
url: "/share/songRedict.do?id=4616853720955750644&source=0&token=aefb7e82a9638f106a3b555c47301623"
}
];
"
JSON.parse(a)
(program):2 Uncaught SyntaxError: Unexpected token s
at Object.parse (native)
at <anonymous>:2:6
at Object.InjectedScript._evaluateOn (<anonymous>:895:140)
at Object.InjectedScript._evaluateAndWrap (<anonymous>:828:34)
at Object.InjectedScript.evaluate (<anonymous>:694:21)