1个回答
展开全部
js调用json?好抽象的说法,
我按照我的理解写点东西吧,希望对你有点用处,
var question = {
"questions1":[{"number":"1","subject":"choose one bus","answer":"bus1"},
{"number":"2","subject":"get one pen","answer":"pen1"},
{"number":"3","subject":"take one apple","answer":"apple1"}
],
"questions2":[{"number":"5","subject":"have one cake","answer":"cake1"},
{"number":"6","subject":"yes or no","answer":"yes"},
{"number":"7","subject":"understand one or two","answer":"two"}
],
}上面这些就是一个js的json变量声明,js取上面json的值的方式如下
question.questions1[1].number的值是2,取值对应是question代表json变量名,questions1[1]表示上面json中第一个数组questions1的第二个值 {"number":"2","subject":"get one pen","answer":"pen1"},
number就是取其中的number的值,可以看到值是2。以上就是js中对json变量中的取值形式是如何的,修改某个地方的值直接用赋值方式如question.questions2[0].number = 11,就会把上面的json中的questions2中的第一排number为5的值改为11
我按照我的理解写点东西吧,希望对你有点用处,
var question = {
"questions1":[{"number":"1","subject":"choose one bus","answer":"bus1"},
{"number":"2","subject":"get one pen","answer":"pen1"},
{"number":"3","subject":"take one apple","answer":"apple1"}
],
"questions2":[{"number":"5","subject":"have one cake","answer":"cake1"},
{"number":"6","subject":"yes or no","answer":"yes"},
{"number":"7","subject":"understand one or two","answer":"two"}
],
}上面这些就是一个js的json变量声明,js取上面json的值的方式如下
question.questions1[1].number的值是2,取值对应是question代表json变量名,questions1[1]表示上面json中第一个数组questions1的第二个值 {"number":"2","subject":"get one pen","answer":"pen1"},
number就是取其中的number的值,可以看到值是2。以上就是js中对json变量中的取值形式是如何的,修改某个地方的值直接用赋值方式如question.questions2[0].number = 11,就会把上面的json中的questions2中的第一排number为5的值改为11
追问
大概意思能明白,但是能不能写得更详细点呢?就是整个页面的代码。。。我是新手。。很多不太明白
追答
整个页面的代码?其实json只是一个数据存储的工具,和XML是同等性质的,它的用法只是JS与数据之间的交互,页面的使用是把json存储的数据取出来用JS代码处理,和一个直接的变量放在那里处理没多少区别
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询