2012-04-03 12 views
0

문제가 있습니다. 별도의 파일에 JSON 개체 목록이 있지만 데이터 테이블로 파싱하고 싶습니다. 내가 그들을 구문 분석하려고 할 때마다, 나는 여기에 JSON.parse : 예기치 않은 문자 오류

는 JSON은 (자바 스크립트) 객체의 문자열 표현입니다

var myJSONObject = { 
       "orders" : [{ 
        "orderId" : "K2_001", 
        "dueDate" : "04/15/2012", 
        "priority" : 1, 
        "description" : "ORDER K2_001" 
       }, { 
        "orderId" : "K2_002", 
        "dueDate" : "04/20/2012", 
        "priority" : 2, 
        "description" : "ORDER K2_002" 
       }, { 
        "orderId" : "K2_003", 
        "dueDate" : "04/23/2012", 
        "priority" : 3, 
        "description" : "ORDER K2_003" 
       }, { 
        "orderId" : "K2_004", 
        "dueDate" : "04/27/2012", 
        "priority" : 4, 
        "description" : "ORDER K2_004" 
       }, { 
        "orderId" : "K2_005", 
        "dueDate" : "04/30/2012", 
        "priority" : 5, 
        "description" : "ORDER K2_005" 
       }, { 
        "orderId" : "K2_006", 
        "dueDate" : "05/05/2012", 
        "priority" : 6, 
        "description" : "ORDER K2_006" 
       }, { 
        "orderId" : "K2_007", 
        "dueDate" : "05/12/2012", 
        "priority" : 7, 
        "description" : "ORDER K2_007" 
       }, { 
        "orderId" : "K2_008", 
        "dueDate" : "05/14/2012", 
        "priority" : 8, 
        "description" : "ORDER K2_008" 
       }] 
      }; 
      var jsonObject2 = Y.JSON.parse(myJSONObject.responseText); 
+2

는'myJSONObject'는 * 이미 * 객체가이 구문 분석 할 필요가없는 것입니다. –

+2

JSON이 무엇인지 이해하지 못합니다. 'JSON.parse'는 문자열을 객체로 변환합니다. 이미 개체가 있습니다. –

답변

6

코드를입니다 ... 예상치 못한 문자 오류가 발생합니다. A JSON 문자열은 유효한 JavaScript 개체입니다.

예 : 당신의 예에서

var JSON = '{"Hello": "world", "test": [1,2,3]}'; // <= This is JSON, it's a string 
var obj = {"Hello": "world", "test": [1,2,3]}; // <= This is a JavaScript object 

, myJSONObject이미 객체, 그것은 "구문 분석"일 필요는 없습니다.

관련 문제