所以我是javascript的总菜鸟。这是我第一次使用它。我有一些问题将我的JSON字符串转换为一个对象,以便我以后可以在我的代码中使用它。我在我的字符串上调用JSON.parse,但我的代码永远不会执行该行。我一直在使用警报作为一种调试工具,代码永远不会超过这一行:
var toPass = JSON.parse(liveJSON)
我的JSON看起来像这样:
{"request_list": [{"ip": "10.3.1.12","rtt": 0,"protocol": "NAS","time_asserted": 1428382468,"time_executed": 1428382410,},{"ip": "192.168.0.18","rtt": 1,"protocol": "NAS","time_asserted": 1428382468,"time_executed": 1428382410,},{"ip": "69.166.49.126","rtt": 0,"protocol": "NAS","time_asserted": 1428382468,"time_executed": 1428382410,},{"ip": "69.166.48.102","rtt": 0,"protocol": "NAS","time_asserted": 1428382468,"time_executed": 1428382410,},{"ip": "69.166.49.126","rtt": 0,"protocol": "NAS","time_asserted": 1428382468,"time_executed": 1428382440,},{"ip": "10.3.1.12","rtt": 0,"protocol": "NAS","time_asserted": 1428382468,"time_executed": 1428382440,},{"ip": "69.166.48.102","rtt": 0,"protocol": "NAS","time_asserted": 1428382468,"time_executed": 1428382440,},{"ip": "100.43.91.14","rtt": 81,"protocol": "HTTP","time_asserted": 1428382734,"time_executed": 1428382680,},{"ip": "69.166.49.126","rtt": 141,"protocol": "HTTP","time_asserted": 1428382734,"time_executed": 1428382680,},{"ip": "10.10.0.119","rtt": 0,"protocol": "HTTP","time_asserted": 1428382734,"time_executed": 1428382710,},{"ip": "10.3.1.12","rtt": 0,"protocol": "NAS","time_asserted": 1428382734,"time_executed": 1428382680,},{"ip": "69.166.54.200","rtt": 0,"protocol": "NAS","time_asserted": 1428382734,"time_executed": 1428382680,},{"ip": "69.166.49.126","rtt": 0,"protocol": "NAS","time_asserted": 1428382734,"time_executed": 1428382680,},{"ip": "69.166.48.102","rtt": 0,"protocol": "NAS","time_asserted": 1428382734,"time_exe...,},{"ip": "69.166.48.102","rtt": 0,"protocol": "NAS","time_asserted": 1428384067,"time_executed": 1428384030,},{"ip": "10.3.1.12","rtt": 0,"protocol": "NAS","time_asserted": 1428384067,"time_executed": 1428384030,},{"ip": "69.166.49.126","rtt": 0,"protocol": "NAS","time_asserted": 1428384067,"time_executed": 1428384030,},{"ip": "69.166.48.102","rtt": 0,"protocol": "NAS","time_asserted": 1428384067,"time_executed": 1428384060,},{"ip": "10.3.1.12","rtt": 0,"protocol": "NAS","time_asserted": 1428384067,"time_executed": 1428384060,},{"ip": "69.166.49.126","rtt": 0,"protocol": "NAS","time_asserted": 1428384067,"time_executed": 1428384060,},{"ip": "10.99.0.190","rtt": 0,"protocol": "HTTP","time_asserted": 1428384201,"time_executed": 1428384180,},{"ip": "69.166.48.102","rtt": 0,"protocol": "NAS","time_asserted": 1428384201,"time_executed": 1428384150,},{"ip": "10.3.1.12","rtt": 0,"protocol": "NAS","time_asserted": 1428384201,"time_executed": 1428384150,},{"ip": "69.166.49.126","rtt": 0,"protocol": "NAS","time_asserted": 1428384201,"time_executed": 1428384150,},{"ip": "69.166.48.102","rtt": 0,"protocol": "NAS","time_asserted": 1428384201,"time_executed": 1428384180,},{"ip": "10.3.1.12","rtt": 0,"protocol": "NAS","time_asserted": 1428384201,"time_executed": 1428384180,},{"ip": "69.166.49.126","rtt": 0,"protocol": "NAS","time_asserted": 1428384201,"time_executed": 1428384180,},{"ip": "69.166.54.200","rtt": 0,"protocol": "DB","time_asserted": 1428384201,"time_executed": 1428384150,}]}
答案 0 :(得分:1)
您的'json'数据无效(但在javascript中有效)
例如:
... "time_executed": 1428384150,}]}
标准JSON中不允许使用最后一个逗号
你应该使用标准的JSON库来构建你的json字符串。
在json中有些无效,但在javascript中有效:
[{},]
{ {}, }
答案 1 :(得分:0)
每个,
值后,您不能有"time_executed"
个跟踪。您的JSON无效。
答案 2 :(得分:0)
JSON解析器http://json.parser.online.fr/也是检查JSON结构是否正确的另一个好网站。