2011-01-19 3 views
1

jsonlint.com왜 장고를 할 때이 자바 스크립트 오류가 발생합니까?

에 따라 유효한 json 있습니다. 내 자바 스크립트에서 이렇게 :

var params = JSON.parse('{{ all_params_in_json }}'); 

그리고 난이 오류가 발생합니다.

Uncaught SyntaxError: Unexpected token ILLEGAL 
(anonymous function) 

왜? 내 json이 유효합니다. 나는 표준 json2 라이브러리를 사용하고있다.

내 json은 다음과 같습니다.

{ 
    "browser_location": "Sausalito", 
    "browser_distance": 5, 
    "users_who_voted": [ 

    ], 
    "author": { 
     "username": "swnn", 
     "bio": "I'm the CEO at Twitter. Prior to Twitter, I cofounded FeedBurner (acquired by Google). I'm an investor and Advisor in a few start-ups including about.me.\r\n \r\nI used to perform with Chicago\u2019s Annoyance Theater and at various comedy festivals in Edinburgh, Montreal and other distant lands. I recently left the cold winters of Chicago for Marin County's sunshine.", 
     "first_name": "feli", 
     "last_name": "twan", 
     "avatar_url": "http://s3.amazonaws.com/fabletest/937ypvlchrd2e5z1a0sq", 
     "is_active": true, 
     "is_superuser": false, 
     "is_staff": false, 
     "last_login": 1295410796.0, 
     "location": "San Francisco", 
     "fullname": "twan Chan", 
     "id": 1, 
     "date_joined": 1293678904.0 
    }, 
    "total_views": 227, 
    "comments": [ 
     { 
      "body": "sdfasdf", 
      "created_at": 1295317816.0, 
      "user": { 
       "username": "swnn", 
       "bio": "I'm the CEO at Twitter. Prior to Twitter, I cofounded FeedBurner (acquired by Google). I'm an investor and Advisor in a few start-ups including about.me.\r\n \r\nI used to perform with Chicago\u2019s Annoyance Theater and at various comedy festivals in Edinburgh, Montreal and other distant lands. I recently left the cold winters of Chicago for Marin County's sunshine.", 
       "first_name": "feli", 
       "last_name": "twan", 
       "avatar_url": "http://s3.amazonaws.com/fabletest/937ypvlchrd2e5z1a0sq", 
       "is_active": true, 
       "is_superuser": false, 
       "is_staff": false, 
       "last_login": 1295410796.0, 
       "location": "San Francisco", 
       "fullname": "twan Chan", 
       "id": 1, 
       "date_joined": 1293678904.0 
      } 
     }, 
     { 
      "body": "sdfasdfasd", 
      "created_at": 1295317900.0, 
      "user": { 
       "username": "swnn", 
       "bio": "I'm the CEO at Twitter. Prior to Twitter, I cofounded FeedBurner (acquired by Google). I'm an investor and Advisor in a few start-ups including about.me.\r\n \r\nI used to perform with Chicago\u2019s Annoyance Theater and at various comedy festivals in Edinburgh, Montreal and other distant lands. I recently left the cold winters of Chicago for Marin County's sunshine.", 
       "first_name": "feli", 
       "last_name": "twan", 
       "avatar_url": "http://s3.amazonaws.com/fabletest/937ypvlchrd2e5z1a0sq", 
       "is_active": true, 
       "is_superuser": false, 
       "is_staff": false, 
       "last_login": 1295410796.0, 
       "location": "San Francisco", 
       "fullname": "twan Chan", 
       "id": 1, 
       "date_joined": 1293678904.0 
      } 
     }, 
     { 
      "body": "sdasdasD", 
      "created_at": 1295323153.0, 
      "user": { 
       "username": "swnn", 
       "bio": "I'm the CEO at Twitter. Prior to Twitter, I cofounded FeedBurner (acquired by Google). I'm an investor and Advisor in a few start-ups including about.me.\r\n \r\nI used to perform with Chicago\u2019s Annoyance Theater and at various comedy festivals in Edinburgh, Montreal and other distant lands. I recently left the cold winters of Chicago for Marin County's sunshine.", 
       "first_name": "feli", 
       "last_name": "twan", 
       "avatar_url": "http://s3.amazonaws.com/fabletest/937ypvlchrd2e5z1a0sq", 
       "is_active": true, 
       "is_superuser": false, 
       "is_staff": false, 
       "last_login": 1295410796.0, 
       "location": "San Francisco", 
       "fullname": "twan Chan", 
       "id": 1, 
       "date_joined": 1293678904.0 
      } 
     }, 
     { 
      "body": "The picture in this submission is not accurate", 
      "created_at": 1295325473.0, 
      "user": { 
       "username": "swnn", 
       "bio": "I'm the CEO at Twitter. Prior to Twitter, I cofounded FeedBurner (acquired by Google). I'm an investor and Advisor in a few start-ups including about.me.\r\n \r\nI used to perform with Chicago\u2019s Annoyance Theater and at various comedy festivals in Edinburgh, Montreal and other distant lands. I recently left the cold winters of Chicago for Marin County's sunshine.", 
       "first_name": "feli", 
       "last_name": "twan", 
       "avatar_url": "http://s3.amazonaws.com/fabletest/937ypvlchrd2e5z1a0sq", 
       "is_active": true, 
       "is_superuser": false, 
       "is_staff": false, 
       "last_login": 1295410796.0, 
       "location": "San Francisco", 
       "fullname": "twan Chan", 
       "id": 1, 
       "date_joined": 1293678904.0 
      } 
     }, 
     { 
      "body": "This submission is not useful to me.", 
      "created_at": 1295325491.0, 
      "user": { 
       "username": "swnn", 
       "bio": "I'm the CEO at Twitter. Prior to Twitter, I cofounded FeedBurner (acquired by Google). I'm an investor and Advisor in a few start-ups including about.me.\r\n \r\nI used to perform with Chicago\u2019s Annoyance Theater and at various comedy festivals in Edinburgh, Montreal and other distant lands. I recently left the cold winters of Chicago for Marin County's sunshine.", 
       "first_name": "feli", 
       "last_name": "twan", 
       "avatar_url": "http://s3.amazonaws.com/fabletest/937ypvlchrd2e5z1a0sq", 
       "is_active": true, 
       "is_superuser": false, 
       "is_staff": false, 
       "last_login": 1295410796.0, 
       "location": "San Francisco", 
       "fullname": "twan Chan", 
       "id": 1, 
       "date_joined": 1293678904.0 
      } 
     }, 
     { 
      "body": "lcokc", 
      "created_at": 1295344958.0, 
      "user": { 
       "username": "swnn", 
       "bio": "I'm the CEO at Twitter. Prior to Twitter, I cofounded FeedBurner (acquired by Google). I'm an investor and Advisor in a few start-ups including about.me.\r\n \r\nI used to perform with Chicago\u2019s Annoyance Theater and at various comedy festivals in Edinburgh, Montreal and other distant lands. I recently left the cold winters of Chicago for Marin County's sunshine.", 
       "first_name": "feli", 
       "last_name": "twan", 
       "avatar_url": "http://s3.amazonaws.com/fabletest/937ypvlchrd2e5z1a0sq", 
       "is_active": true, 
       "is_superuser": false, 
       "is_staff": false, 
       "last_login": 1295410796.0, 
       "location": "San Francisco", 
       "fullname": "twan Chan", 
       "id": 1, 
       "date_joined": 1293678904.0 
      } 
     }, 
     { 
      "body": "gagaga", 
      "created_at": 1295345040.0, 
      "user": { 
       "username": "swnn", 
       "bio": "I'm the CEO at Twitter. Prior to Twitter, I cofounded FeedBurner (acquired by Google). I'm an investor and Advisor in a few start-ups including about.me.\r\n \r\nI used to perform with Chicago\u2019s Annoyance Theater and at various comedy festivals in Edinburgh, Montreal and other distant lands. I recently left the cold winters of Chicago for Marin County's sunshine.", 
       "first_name": "feli", 
       "last_name": "twan", 
       "avatar_url": "http://s3.amazonaws.com/fabletest/937ypvlchrd2e5z1a0sq", 
       "is_active": true, 
       "is_superuser": false, 
       "is_staff": false, 
       "last_login": 1295410796.0, 
       "location": "San Francisco", 
       "fullname": "twan Chan", 
       "id": 1, 
       "date_joined": 1293678904.0 
      } 
     }, 
     { 
      "body": "wwwww", 
      "created_at": 1295345084.0, 
      "user": { 
       "username": "swnn", 
       "bio": "I'm the CEO at Twitter. Prior to Twitter, I cofounded FeedBurner (acquired by Google). I'm an investor and Advisor in a few start-ups including about.me.\r\n \r\nI used to perform with Chicago\u2019s Annoyance Theater and at various comedy festivals in Edinburgh, Montreal and other distant lands. I recently left the cold winters of Chicago for Marin County's sunshine.", 
       "first_name": "feli", 
       "last_name": "twan", 
       "avatar_url": "http://s3.amazonaws.com/fabletest/937ypvlchrd2e5z1a0sq", 
       "is_active": true, 
       "is_superuser": false, 
       "is_staff": false, 
       "last_login": 1295410796.0, 
       "location": "San Francisco", 
       "fullname": "twan Chan", 
       "id": 1, 
       "date_joined": 1293678904.0 
      } 
     }, 
     { 
      "body": "sadfasdfasdf", 
      "created_at": 1295345136.0, 
      "user": { 
       "username": "swnn", 
       "bio": "I'm the CEO at Twitter. Prior to Twitter, I cofounded FeedBurner (acquired by Google). I'm an investor and Advisor in a few start-ups including about.me.\r\n \r\nI used to perform with Chicago\u2019s Annoyance Theater and at various comedy festivals in Edinburgh, Montreal and other distant lands. I recently left the cold winters of Chicago for Marin County's sunshine.", 
       "first_name": "feli", 
       "last_name": "twan", 
       "avatar_url": "http://s3.amazonaws.com/fabletest/937ypvlchrd2e5z1a0sq", 
       "is_active": true, 
       "is_superuser": false, 
       "is_staff": false, 
       "last_login": 1295410796.0, 
       "location": "San Francisco", 
       "fullname": "twan Chan", 
       "id": 1, 
       "date_joined": 1293678904.0 
      } 
     }, 
     { 
      "body": "asdasdf", 
      "created_at": 1295345253.0, 
      "user": { 
       "username": "swnn", 
       "bio": "I'm the CEO at Twitter. Prior to Twitter, I cofounded FeedBurner (acquired by Google). I'm an investor and Advisor in a few start-ups including about.me.\r\n \r\nI used to perform with Chicago\u2019s Annoyance Theater and at various comedy festivals in Edinburgh, Montreal and other distant lands. I recently left the cold winters of Chicago for Marin County's sunshine.", 
       "first_name": "feli", 
       "last_name": "twan", 
       "avatar_url": "http://s3.amazonaws.com/fabletest/937ypvlchrd2e5z1a0sq", 
       "is_active": true, 
       "is_superuser": false, 
       "is_staff": false, 
       "last_login": 1295410796.0, 
       "location": "San Francisco", 
       "fullname": "twan Chan", 
       "id": 1, 
       "date_joined": 1293678904.0 
      } 
     }, 
     { 
      "body": "sdfasdfasd", 
      "created_at": 1295345279.0, 
      "user": { 
       "username": "swnn", 
       "bio": "I'm the CEO at Twitter. Prior to Twitter, I cofounded FeedBurner (acquired by Google). I'm an investor and Advisor in a few start-ups including about.me.\r\n \r\nI used to perform with Chicago\u2019s Annoyance Theater and at various comedy festivals in Edinburgh, Montreal and other distant lands. I recently left the cold winters of Chicago for Marin County's sunshine.", 
       "first_name": "feli", 
       "last_name": "twan", 
       "avatar_url": "http://s3.amazonaws.com/fabletest/937ypvlchrd2e5z1a0sq", 
       "is_active": true, 
       "is_superuser": false, 
       "is_staff": false, 
       "last_login": 1295410796.0, 
       "location": "San Francisco", 
       "fullname": "twan Chan", 
       "id": 1, 
       "date_joined": 1293678904.0 
      } 
     }, 
     { 
      "body": "asdfasdf", 
      "created_at": 1295345358.0, 
      "user": { 
       "username": "swnn", 
       "bio": "I'm the CEO at Twitter. Prior to Twitter, I cofounded FeedBurner (acquired by Google). I'm an investor and Advisor in a few start-ups including about.me.\r\n \r\nI used to perform with Chicago\u2019s Annoyance Theater and at various comedy festivals in Edinburgh, Montreal and other distant lands. I recently left the cold winters of Chicago for Marin County's sunshine.", 
       "first_name": "feli", 
       "last_name": "twan", 
       "avatar_url": "http://s3.amazonaws.com/fabletest/937ypvlchrd2e5z1a0sq", 
       "is_active": true, 
       "is_superuser": false, 
       "is_staff": false, 
       "last_login": 1295410796.0, 
       "location": "San Francisco", 
       "fullname": "twan Chan", 
       "id": 1, 
       "date_joined": 1293678904.0 
      } 
     }, 
     { 
      "body": "foxed", 
      "created_at": 1295345790.0, 
      "user": { 
       "username": "swnn", 
       "bio": "I'm the CEO at Twitter. Prior to Twitter, I cofounded FeedBurner (acquired by Google). I'm an investor and Advisor in a few start-ups including about.me.\r\n \r\nI used to perform with Chicago\u2019s Annoyance Theater and at various comedy festivals in Edinburgh, Montreal and other distant lands. I recently left the cold winters of Chicago for Marin County's sunshine.", 
       "first_name": "feli", 
       "last_name": "twan", 
       "avatar_url": "http://s3.amazonaws.com/fabletest/937ypvlchrd2e5z1a0sq", 
       "is_active": true, 
       "is_superuser": false, 
       "is_staff": false, 
       "last_login": 1295410796.0, 
       "location": "San Francisco", 
       "fullname": "twan Chan", 
       "id": 1, 
       "date_joined": 1293678904.0 
      } 
     }, 
     { 
      "body": "Is this really the right thing? I mean...after thinking about it. ist's just not very cool", 
      "created_at": 1295345827.0, 
      "user": { 
       "username": "swnn", 
       "bio": "I'm the CEO at Twitter. Prior to Twitter, I cofounded FeedBurner (acquired by Google). I'm an investor and Advisor in a few start-ups including about.me.\r\n \r\nI used to perform with Chicago\u2019s Annoyance Theater and at various comedy festivals in Edinburgh, Montreal and other distant lands. I recently left the cold winters of Chicago for Marin County's sunshine.", 
       "first_name": "feli", 
       "last_name": "twan", 
       "avatar_url": "http://s3.amazonaws.com/fabletest/937ypvlchrd2e5z1a0sq", 
       "is_active": true, 
       "is_superuser": false, 
       "is_staff": false, 
       "last_login": 1295410796.0, 
       "location": "San Francisco", 
       "fullname": "twan Chan", 
       "id": 1, 
       "date_joined": 1293678904.0 
      } 
     }, 
     { 
      "body": "s this really the right thing? I mean...after thinking about it. ist's just not very cool", 
      "created_at": 1295345871.0, 
      "user": { 
       "username": "swnn", 
       "bio": "I'm the CEO at Twitter. Prior to Twitter, I cofounded FeedBurner (acquired by Google). I'm an investor and Advisor in a few start-ups including about.me.\r\n \r\nI used to perform with Chicago\u2019s Annoyance Theater and at various comedy festivals in Edinburgh, Montreal and other distant lands. I recently left the cold winters of Chicago for Marin County's sunshine.", 
       "first_name": "feli", 
       "last_name": "twan", 
       "avatar_url": "http://s3.amazonaws.com/fabletest/937ypvlchrd2e5z1a0sq", 
       "is_active": true, 
       "is_superuser": false, 
       "is_staff": false, 
       "last_login": 1295410796.0, 
       "location": "San Francisco", 
       "fullname": "twan Chan", 
       "id": 1, 
       "date_joined": 1293678904.0 
      } 
     }, 
     { 
      "body": "his song really suck.s", 
      "created_at": 1295346108.0, 
      "user": { 
       "username": "swnn", 
       "bio": "I'm the CEO at Twitter. Prior to Twitter, I cofounded FeedBurner (acquired by Google). I'm an investor and Advisor in a few start-ups including about.me.\r\n \r\nI used to perform with Chicago\u2019s Annoyance Theater and at various comedy festivals in Edinburgh, Montreal and other distant lands. I recently left the cold winters of Chicago for Marin County's sunshine.", 
       "first_name": "feli", 
       "last_name": "twan", 
       "avatar_url": "http://s3.amazonaws.com/fabletest/937ypvlchrd2e5z1a0sq", 
       "is_active": true, 
       "is_superuser": false, 
       "is_staff": false, 
       "last_login": 1295410796.0, 
       "location": "San Francisco", 
       "fullname": "twan Chan", 
       "id": 1, 
       "date_joined": 1293678904.0 
      } 
     }, 
     { 
      "body": "asdfasdf", 
      "created_at": 1295383689.0, 
      "user": { 
       "username": "swnn", 
       "bio": "I'm the CEO at Twitter. Prior to Twitter, I cofounded FeedBurner (acquired by Google). I'm an investor and Advisor in a few start-ups including about.me.\r\n \r\nI used to perform with Chicago\u2019s Annoyance Theater and at various comedy festivals in Edinburgh, Montreal and other distant lands. I recently left the cold winters of Chicago for Marin County's sunshine.", 
       "first_name": "feli", 
       "last_name": "twan", 
       "avatar_url": "http://s3.amazonaws.com/fabletest/937ypvlchrd2e5z1a0sq", 
       "is_active": true, 
       "is_superuser": false, 
       "is_staff": false, 
       "last_login": 1295410796.0, 
       "location": "San Francisco", 
       "fullname": "twan Chan", 
       "id": 1, 
       "date_joined": 1293678904.0 
      } 
     }, 
     { 
      "body": "asdfasdf", 
      "created_at": 1295410874.0, 
      "user": { 
       "username": "swnn", 
       "bio": "I'm the CEO at Twitter. Prior to Twitter, I cofounded FeedBurner (acquired by Google). I'm an investor and Advisor in a few start-ups including about.me.\r\n \r\nI used to perform with Chicago\u2019s Annoyance Theater and at various comedy festivals in Edinburgh, Montreal and other distant lands. I recently left the cold winters of Chicago for Marin County's sunshine.", 
       "first_name": "feli", 
       "last_name": "twan", 
       "avatar_url": "http://s3.amazonaws.com/fabletest/937ypvlchrd2e5z1a0sq", 
       "is_active": true, 
       "is_superuser": false, 
       "is_staff": false, 
       "last_login": 1295410796.0, 
       "location": "San Francisco", 
       "fullname": "twan Chan", 
       "id": 1, 
       "date_joined": 1293678904.0 
      } 
     }, 
     { 
      "body": "Is this all right?", 
      "created_at": 1295411376.0, 
      "user": { 
       "username": "swnn", 
       "bio": "I'm the CEO at Twitter. Prior to Twitter, I cofounded FeedBurner (acquired by Google). I'm an investor and Advisor in a few start-ups including about.me.\r\n \r\nI used to perform with Chicago\u2019s Annoyance Theater and at various comedy festivals in Edinburgh, Montreal and other distant lands. I recently left the cold winters of Chicago for Marin County's sunshine.", 
       "first_name": "feli", 
       "last_name": "twan", 
       "avatar_url": "http://s3.amazonaws.com/fabletest/937ypvlchrd2e5z1a0sq", 
       "is_active": true, 
       "is_superuser": false, 
       "is_staff": false, 
       "last_login": 1295410796.0, 
       "location": "San Francisco", 
       "fullname": "twan Chan", 
       "id": 1, 
       "date_joined": 1293678904.0 
      } 
     } 
    ], 
    "initial_vote": 0, 
    "browser_lat": 37.848800659179688, 
    "post": { 
     "ip": "174.129.251.48", 
     "thumb_500x500": { 
      "url": "http://s3.amazonaws.com/fabletest/bv2814ghmd", 
      "width": 500, 
      "height": 351 
     }, 
     "date": 1295154531.334044, 
     "thumb_original": { 
      "url": "http://farm6.static.flickr.com/5249/5336976806_481943d486_b.jpg", 
      "width": 779, 
      "height": 548 
     }, 
     "total_views": 227, 
     "thumb_230x480": { 
      "url": "http://s3.amazonaws.com/fabletest/4e7h95rt3f", 
      "width": 230, 
      "height": 480 
     }, 
     "test_set": "g2", 
     "title": "Maybe. . .we were supposed to meet the wrong people before meeting the right one so that, when we finally meet the right person, we will know how to be grateful for that gift ...", 
     "stamp": "bf305695ca51b5390dc0c2f34c074215", 
     "pop_score": 241.59687499999995, 
     "thumb_640x640": { 
      "url": "http://s3.amazonaws.com/fabletest/4q15bsgmt2", 
      "width": 640, 
      "height": 450 
     }, 
     "image_direction": "landscape", 
     "author_username": "swnn", 
     "thumb_230x230": { 
      "url": "http://s3.amazonaws.com/fabletest/x0dq7gzb4f", 
      "width": 230, 
      "height": 230 
     }, 
     "description": "sooc with Shana Rae overlay ....", 
     "top_score": 0.90000000000000002, 
     "active": true, 
     "original_file": "http://farm6.static.flickr.com/5249/5336976806_481943d486_b.jpg", 
     "loc_utm": [ 
      500000.0, 
      6317527.4506855672 
     ], 
     "_id": { 
      "$oid": "4d327d658aad6919be0000d5" 
     }, 
     "sizes": [ 
      { 
       "url": "http://farm6.static.flickr.com/5249/5336976806_481943d486_b.jpg", 
       "width": 779, 
       "height": 548 
      }, 
      { 
       "url": "http://s3.amazonaws.com/fabletest/4q15bsgmt2", 
       "width": 640, 
       "height": 450 
      }, 
      { 
       "url": "http://s3.amazonaws.com/fabletest/bv2814ghmd", 
       "width": 500, 
       "height": 351 
      }, 
      { 
       "url": "http://s3.amazonaws.com/fabletest/x0dq7gzb4f", 
       "width": 230, 
       "height": 230 
      }, 
      { 
       "url": "http://s3.amazonaws.com/fabletest/4e7h95rt3f", 
       "width": 230, 
       "height": 480 
      }, 
      { 
       "url": "http://s3.amazonaws.com/fabletest/g1pmqk7r6y", 
       "width": 480, 
       "height": 230 
      } 
     ], 
     "loc_latlong": [ 
      57.0, 
      -99.0 
     ], 
     "thumb_480x230": { 
      "url": "http://s3.amazonaws.com/fabletest/g1pmqk7r6y", 
      "width": 480, 
      "height": 230 
     }, 
     "processed": true, 
     "author_id": 1, 
     "content_id": 13259, 
     "thumb_500x500_low": { 
      "url": "http://s3.amazonaws.com/fabletest/oznumyqve7", 
      "width": 500, 
      "quality": 4, 
      "height": 351 
     } 
    }, 
    "browser_long": -122.53489685058594, 
    "pos_votes_count": 0 
} 
+0

Firebug를 사용하고 여기에 중단 점을 설정할 수 있으며 따옴표로 무엇을 얻었는지 확인할 수 있습니까? – Spacedman

답변

2

당신은해야한다.

0

소리 :

내 JSON이입니다. 이것을 확인하십시오. 브라우저에 따라 합법적인지 여부에 달려 있습니다. 변수가 문자열을 종료하고 모든 지옥 나누기 느슨한

var params = JSON.parse('{{ all_params_in_json|escapejs }}'); 

그렇지 않으면 예컨대 '문자 all_params_in_json 내부 :

+0

내 json을 확인하여 내가 가지고있는 잘못된 문자를 볼 수 있습니까? (해당 json 유효합니다) – TIMEX

+0

거기에 어떤 문제가 보지 마세요. 어떻게 JSON을 JSON.parse()에 실제로 제공 했습니까? 문자열에는 질문에 게시 할 때 오류가 발생하는 문자가 포함되어 있습니다 (', 토마스의 대답을 참조하십시오. 또한 줄 바꿈이 오류를 유발할 수 있습니다). –

관련 문제