【初心者】
jsonをjavascriptで取得して、DOM操作をしたいです。
Jsonは正しいと思うのですが、以下のような構文エラーが出ます。
XML パースエラー: 構文エラーです。
URL: /product/item.json
行番号: 1, 列番号: 1:
item.json:1:1
ブラウザはFirefoxを使いました。
以下のパースエラーと出るのですが、jsonの間違いが見当たらないです。
それとも他のところがエラーなのでしょうか?
よろしくお願い致します。
json
item.json
1[ 2 { 3 "code": "0001", 4 "name": "EV-02", 5 "price": 1500 6 }, 7 { 8 "code": "0002", 9 "name": "NR-07", 10 "price": 2500 11 }, 12 { 13 "code": "0003", 14 "name": "WR-03", 15 "price": 3500 16 } 17] 18
htmlと、jsも載せておきますね。
html
index.html
1<!DOCTYPE html> 2<html lang="ja" dir="ltr"> 3 <head> 4 <meta charset="utf-8"> 5 <title></title> 6 <script src="http://code.jquery.com/jquery-2.0.3.min.js"></script> 7 <script src="./index.js"></script> 8 </head> 9 <body> 10 <table id="dataTable"> 11 <tr> 12 <th>code</th> 13 <th>name</th> 14 <th>price</th> 15 </tr> 16 </table> 17 </body> 18</html> 19
js
index.js
1$(function(){ 2 $.getJSON("item.json", 3 function(data) { 4 for(var i=0; i<data.length; i++){ 5 $("#dataTable").append("<tr></tr>") 6 .find("tr:last") 7 .append("<td>" + data[i].code + "</td>") 8 .append("<td>" + data[i].naem + "</td>") 9 .append("<td>" + data[i].price + "</td>"); 10 } 11 } 12); 13}); 14
回答3件
あなたの回答
tips
プレビュー