使用JavaScript或jQuery读取数组JSON
Reading array JSON with JavaScript or jQuery
我有下一个数组json,我如何读取它?我已经尝试过document.write(arr)
,它有效,但如果我放document.write(arr[0].Category)
,它会显示undefined
,
var arr = [{"Category":
{"cell":{"question1":{"que1":"What is the cell?"},
"option1":{"op1":"The cell is the basic structural and functional unit",
"op2":"is a fictional supervillain in Dragon Ball"},"answerswer1":"opt1"}}},
{"Category":{"Mars":{"question1":{"que1":"How many moons does Mars?"},
"option1":{"op1":"5","op2":"2"},"answerswer1":"opt2"}}}]
顺便说一句,数组格式很好,因为如果我执行document.write(arr)
,它将返回相同的数组
代码确实有效。看:http://jsfiddle.net/5GTWp/
console.log(arr[0].Category);
document.write(arr[0].Category.cell.question1.que1);
记录对象,
写入:What is the cell?
document.write(arr[0].Category)
写入[object Object]
,未定义。
问题不在给定的代码中。
编辑:更多信息。OP在评论中添加了"我需要说,que数组是从json文件中提取的,我做了一个var arr=json.stringfy(arrjson)"
如果你把arr做成一根绳子,它是行不通的。你举的例子!=你的问题。
document.write(arrjson[0].Category);
是您要查找的对象。
相关文章:
- 为DataTables aoColumnDefs创建JavaScript数组(JSON格式)
- 使用 Javascript 将行添加到数组 json
- PHP数组JSON编码和该对象在ExtJs中解码
- 数组json转换为数组json
- 将Blob文本转换为Javascript中的数组/JSON对象
- 如何合并这些数组/json 对象
- 尝试从数组 JSON 键中删除引号
- JavaScript 中的数组 JSON
- 在数组 JSON 格式的 JavaScript 变量末尾添加新地址
- 如何访问这个Javascript数组(JSON对象?)
- rails传递记录数组(JSON)
- 按值提取对象/数组json vs数组
- 获取具有子数组json值的数组的值
- Object对象数组Json.字符串数组的字符串化
- 如何在Ext js 4.1中过滤数组json
- PHP -多维数组Json
- 正在分析数组Json以选择Tag
- 试图将字符串数据转换为数值数据,将数据放入数组的数组(Json)
- 从数组json、javascript中的specf值中删除引号
- 使用JavaScript或jQuery读取数组JSON