2016-06-23 4 views
0

である私の現在のコード:JSONLintでこのエラー生成JSONの構文およびだからここにエラー

var training = { 
"onlineCourses": [ 
    { 
     "name":"Udacity" 
     "subjects":["HTML","CSS","JS","Python"] 
     "nanodegrees":["Intro to Programming","Front-End Web Developer"] 
    } 
], 
"certifications": [ 
    { 
     "company":"Cisco" 
     "name":"Certified Certified Network Associate (CCNA)" 
     "subject":"Routing and Networking" 
    }, 
    { 
     "company":"CompTIA" 
     "name":["A+","Network+"] 
     "subject":["General IT","Routing and Networking"] 
    } 
] 
} 

:私はこのコードが必要私は取っているクラスでは、第二

Error: Parse error on line 3: 
..."name": "Udacity" "subjects": ["HTML", 
----------------------^ 
Expecting 'EOF', '}', ':', ',', ']', got 'STRING' 

を、それらの例では、次のようなコードを記述する必要があることを暗示しています。

var training = { 
    "onlineCourses": [ 
     { 
      "name":"Udacity" 
      "subjects":["HTML","CSS","JS","Python"] 
      "nanodegrees":["Intro to Programming","Front-End Web Developer"] 
     } 
    ] 
}, 
    "certifications": [ 
     { 
      "company":"Cisco" 
      "name":"Certified Certified Network Associate (CCNA)" 
      "subject":"Routing and Networking" 
     }, 
     { 
      "company":"CompTIA" 
      "name":["A+","Network+"] 
      "subject":["General IT","Routing and Networking"] 
     } 
    ] 

最初の{ lineCourses配列とcertifications配列は{}のセットの中にありません。これは私には当てはまらないもので、私は彼らがクラスでタイプミスをしたと考えました。私はそれを訂正していますか?

私は同じエラーを取得いずれかの方法:

Error: Parse error on line 3: 
..."name": "Udacity" "subjects": ["HTML", 
----------------------^ 
Expecting 'EOF', '}', ':', ',', ']', got 'STRING' 
+4

各キーの後に '、'がありません: 'value' –

答えて

0

洗面所独立オブジェクト内の複数のプロパティを割り当てることがカンマで各キーと値のペア(、)

{ 
    "name":"Udacity", 
    "subjects":["HTML","CSS","JS","Python"], 
    "nanodegrees":["Intro to Programming","Front-End Web Developer"] 
} 
0

、コンマ(,)であります各物件を分ける必要があります。あなたのtraining変数の正しい方法は次のとおりです。

var training = { 
    "onlineCourses": [ 
     { 
      "name":"Udacity", 
      "subjects":["HTML","CSS","JS","Python"], 
      "nanodegrees":["Intro to Programming","Front-End Web Developer"] 
     } 
    ], 
    "certifications": [ 
     { 
      "company":"Cisco", 
      "name":"Certified Certified Network Associate (CCNA)", 
      "subject":"Routing and Networking" 
     }, 
     { 
      "company":" CompTIA", 
      "name": ["A+", "Network+"], 
      "subject": ["General IT","Routing and Networking"] 
     } 
    ] 
} 
0

は、(セットの最後を除く)各キーと値のペアの後にカンマを持っている必要があります。

var training = { 
    "onlineCourses": [ 
    { 
     "name": "Udacity", 
     "subjects": [ 
     "HTML", 
     "CSS", 
     "JS", 
     "Python" 
     ], 
     "nanodegrees": [ 
     "Intro to Programming", 
     "Front-End Web Developer" 
     ] 
    } 
    ], 
    "certifications": [ 
    { 
     "company": "Cisco", 
     "name": "Certified Certified Network Associate (CCNA)", 
     "subject": "Routing and Networking" 
    }, 
    { 
     "company": "CompTIA", 
     "name": [ 
     "A+", 
     "Network+" 
     ], 
     "subject": [ 
     "General IT", 
     "Routing and Networking" 
     ] 
    } 
    ] 
} 
0

あなたのJSONは有効ではありません。あなたはいつもここでは、そのようなhttp://jsonlint.com/

としてバリデータを使用してJSONを検証することもできます修正JSONです:

var training = { 
    "onlineCourses": [{ 
     "name": "Udacity", 
     "subjects": ["HTML", "CSS", "JS", "Python"], 
     "nanodegrees": ["Intro to Programming", "Front-End Web Developer"] 
    }], 
    "certifications": [{ 
     "company": "Cisco", 
     "name": "Certified Certified Network Associate (CCNA)", 
     "subject": "Routing and Networking" 
    }, { 
     "company": "CompTIA", 
     "name": ["A+", "Network+"], 
     "subject": ["General IT", "Routing and Networking"] 
    }] 
} 

また、あなたのJSONは同様に無効になります、ご質問の後半部分に答えるために。しかし、第2に、私はこのコードが必要な場所を取っているので、代わりに次のようなコードを書かなければならないことを暗示しています。 isn;

0

有効な構文については、jsonカンマ(、)を分けてください。 例。

{ 
    "name":"Udacity", 
    "subjects":["HTML","CSS"], 
    "nanodegrees":["Intro to Programming","Front-End Web Developer"] 
} 
関連する問題