これはおそらく本当に簡単な質問ですが、私はどこでも答えや説明を見つけることができないようです。ループのためのjsonファイルにマップを接続
私のJSONに配置した画像と名前のマップ(画像ファイルの入っている場所)をどこに、どこに接続しますか?ブラウザのウィンドウで画像を表示する必要があります。 私はJSONとLoopingとJSにとってかなり新しいです。
あなたがそれを調べて、私がそれをどのようにしているのか理解する必要があるなら、ここに私のコードがあります。
JSON;
{ "main_object": {
"imagesJ": ["beak", "cat", "egg", "meel", "milk", "passport", "spoon", "thee"],
"woorden": ["words", "not", "needed", "yet"]
}
}
//JavaScript
var jsonData = "noJson";
var hr = new XMLHttpRequest();
$(document).ready(function() {
var jsonData = 'empty';
$.ajax({
async: false,
url: "./js/data.json",
dataType: 'html',
success: function(response) {
jsonData = JSON.parse(response);
console.log('ok');
imagesJ = jsonData.main_object.imagesJ;
woorden = jsonData.main_object.woorden;
for (i = 0; i < imagesJ.length; i++) {
imagesJ[i] + '.jpg';
// => /img/[imagesJ[x]].jpg
}
},
error: function() {
console.log('JSON could not be loaded.');
}
});
console.log(jsonData);
});
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Sleepopdracht</title>
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>
<script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<link rel="stylesheet" href="http://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.4.0/css/font-awesome.min.css">
<link rel="stylesheet" href="css/css.css">
</head>
<body>
<header>
</header>
<div class="container" id="container">
<div class="images" id="images"></div>
</div>
<footer>
</footer>
<script type="text/javascript" src="js/javascript.js"></script>
</body>
</html>
ありがとう、あなたは理解してもらえました。 –