SyntaxError:JSON解析错误:意外的EOF

时间:2014-02-18 16:40:17

标签: javascript jquery json

我有以下代码行:

data = jQuery.parseJSON(data);

正在创建以下错误...

SyntaxError: JSON Parse error: Unexpected EOF

我无法弄清楚如何识别导致错误的原因。

有什么想法吗?

这是数据......

{
    "element_type": "paint",
    "edit_element_id": "2117",
    "paint_id": "15",
    "paint_editable_data": "zwibbler3.[{\"id\":0,\"type\":\"GroupNode\",\"fillStyle\":\"#cccccc\",\"strokeStyle\":\"#000000\",\"lineWidth\":2,\"shadow\":false,\"matrix\":[1,0,0,1,0,0],\"layer\":\"default\"},{\"id\":1,\"type\":\"PageNode\",\"parent\":0,\"fillStyle\":\"#cccccc\",\"strokeStyle\":\"#000000\",\"lineWidth\":2,\"shadow\":false,\"matrix\":[1,0,0,1,0,0],\"layer\":\"default\"},{\"id\":2,\"type\":\"BrushNode\",\"parent\":1,\"fillStyle\":\"#cccccc\",\"strokeStyle\":\"#000000\",\"lineWidth\":10,\"shadow\":false,\"matrix\":[1,0,0,1,0,0],\"layer\":\"default\",\"points\":[17,21,17,22,17,24,17,28,18,34,37,55,49,59,70,61,89,56,92,55,93,54]},{\"id\":3,\"type\":\"PathNode\",\"parent\":1,\"fillStyle\":\"#e0e0e0\",\"strokeStyle\":\"#000000\",\"lineWidth\":2,\"shadow\":false,\"matrix\":[1,0,0,1,-14,-85],\"layer\":\"default\",\"textFillStyle\":\"#000000\",\"fontName\":\"Arial\",\"fontSize\":20,\"dashes\":\"\",\"smoothness\":0.3,\"sloppiness\":0,\"closed\":true,\"arrowSize\":0,\"arrowStyle\":\"simple\",\"doubleArrow\":false,\"text\":\"\",\"roundRadius\":0,\"commands\":[0,150,100,6,200,150,200,100,6,150,200,200,200,6,100,150,100,200,6,150,100,100,100,7],\"seed\":36934}]",
    "paint_image_data": "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAALwAAAB1CAYAAAD0rovXAAASHklEQVR4Ae1dCXBW1RW+BAKJNAwihMWgkYkN+1JgRG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cBssPHrdp00aFW23POYgZM2ao0aNHq2+++YalchxIAZYCjok4vGNUuqboNDTPBurhp74NNwhds2aN1q6/9957XUvUS8Xbtm1Tw4cP19YUBb6nyvz2Bf7jtB0yj+00o+7qewzq3wMaMZmUlBRtiXHDhg15GnLCz9FMnDhRrVq1Srf9KA5GAmv0C06H4vBOM+q+vhgk8SLwEhAbHR2t0tLSVEZGhqpdu7b7qTuQQl5enpo2bZpasGCBvv8jB9hfB94AtLewHUimVBXi8KXSEhIXE2DleOBpICo2NlYNGjRIpaenB63j09G5b8z8+fP1SSSOSM0FMgE23VwXcXjXKXY9gWZIgY7/BFOKiYlRqampavDgwapFixa85Lvs3btXzZs3T2VlZenbaNAmvqFER9/HE69EHN4rpt1PpzWSeBXoB2jlmpSUpHr16qWhZcuW7ltgSIHLAbhEgjB8SY9Di5xj+CtgeeGXQb3tQ3F429QF7YPc/2YE8AxQR7eS7fsOHTpoE1gMGzXS+r367QqHHD/fsmWLys3N1UI2XwzCV/A48jITOGK47vmhOLznlHuWYDRSegTgMlriPqBQ2Obn4rT4+HgtLH6sn/OBCxcuKG5jp8N4rh8HFnYV6sfBSWBFAJ8j5AZJvos4vO9F4JkBXJDTFegWCJ1einkeenMC2IAwKDfEF4dHyUSo3IN81w+gnuFYv6aHpOdsKThX7BrfQBIRBoSBYGLg/9jYtJnVySp3AAAAAElFTkSuQmCC"
}

可能是问题的大小吗?

3 个答案:

答案 0 :(得分:6)

看起来您正在尝试将文本字符串转换为JSON数据对象。

您可能应该执行以下操作:

  • 而不是使用jQuery.parseJSON(data),而只是使用JSON.parse(data)
  • 您提到的错误表明您传入的是一个空字符串""作为你的数据价值。因此,请检查传递给解析方法的值。
  • 您提及的传入的数据对象将始终导致错误,因为它已经是JSON格式。

解析方法旨在进行以下转换。

JSON.parse("{\"hello\":\"world\"}")返回{hello:'world'}

如果您尝试将对象转换为字符串,可以尝试:

JSON.stringify({hello:'world'})返回"{\"hello\":\"world\"}"

答案 1 :(得分:0)

原因很简单。在脚本中定义JSON时,双引号应由\"表示。 ,不是"

答案 2 :(得分:-2)

也许你可以使用eval方法:

if (data !== null) {
    var json_obj= eval("("+data+")"); //jQuery.parseJSON(data);

    //just for check the the keys     
    var keys = Object.keys(json_obj);
    for (var i = 0; i < keys.length; i++) {
        console.log(keys[i]);
    };
}