就我个人而言,我认为您应该花一些时间来锻造一些实现JSON的东西。
虽然它会,本质上最终是一个数组...... JSON 可能更灵活,您可以根据需要嵌入有关该问题的更多信息。
我怀疑随着时间的推移,您的要求可能会变得更加复杂,并且解析一些 JSON 的额外时间是相当微不足道的。
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN">
<html>
<head>
<title>Simple use of JSON</title>
<script type="text/javascript">
//ultimately this will be in a file that you will access so you don't have to update code when the list changes.
var sentence_json = '{ "sentences" : [{ "sentence" : "Can we go to the park.", "difficulty" : "1" },' +
'{ "sentence" : "Where is the orange cat? Said the big black dog.", "difficulty" : "2" },' +
'{ "sentence" : "We can make the bird fly away if we jump on something.", "difficulty" : "3" },' +
'{ "sentence" : "We can go down to the store with the dog. It is not too far away.", "difficulty" : "3" },' +
'{ "sentence" : "My big yellow cat ate the little black bird.", "difficulty" : "2" },' +
'{ "sentence" : "I like to read my book at school.", "difficulty" : "1" },' +
'{ "sentence" : "We are going to swim at the park.", "difficulty" : "1" }]}';
//this should go through a parser... but for simplest example:
var sentence_obj = eval ("(" + sentence_json + ")");
</script>
</head>
<body>
<p>
Sentence: <span id="sentence"></span><br>
Difficulty: <span id="difficulty"></span><br>
</p>
<script type="text/javascript">
//here's where you use an iterator, but static for the example.
document.getElementById("sentence").innerHTML=sentence_obj.sentences[1].sentence
document.getElementById("difficulty").innerHTML=sentence_obj.sentences[1].difficulty
</script>
</body>
</html>
简单地解决关于它是“最好”的问题,这是一种相对的。这是一个工作示例,我在其中添加了一个按钮“和东西”。