[英]Get elements of json_encoded array in javascript
i passed a json_encode
d array to javascript. 我将json_encode
d数组传递给了javascript。 Now i would like to acces that array to get the different elemtnts. 现在,我想访问该数组以获取不同的元素。
i print it out in the console.log()
and i get this array: 我在console.log()
打印出来,得到这个数组:
array(1) {
[16]=>
array(2) {
[3488]=>
array(1) {
[0]=>
array(2) {
["article_no_internal"]=>
string(6) "999184"
["article_name_internal"]=>
string(29) "Geschenkbox Kerzenschein 2011"
}
}
[2615]=>
array(1) {
[0]=>
array(2) {
["article_no_internal"]=>
string(6) "700469"
["article_name_internal"]=>
string(29) "Hotelscheck RomantischeTagef2"
}
}
}
}
This is about right. 这是正确的。 How can i access the article_name of the second array, with the ID 2615? 如何访问ID为2615的第二个数组的article_name?
found a related question here reading a jsone object , hope for some better explebation or answer. 在阅读jsone对象时发现了一个相关问题,希望能得到更好的解释或答案。 Thanks. 谢谢。
EDIT: 编辑:
As it seems i made a mistake, i showed a php var_dump in the console. 看来我犯了一个错误,我在控制台中显示了一个php var_dump。 When i try to show the javascript array in the console i get undefined. 当我尝试在控制台中显示javascript数组时,我无法定义。
Since JSON means "JavaScript Object Notation" you don't need to do anything to access the object's items. 由于JSON表示“ JavaScript对象表示法”,因此您无需执行任何操作即可访问对象的项目。
For example you can access: 例如,您可以访问:
jsonObject[2615][0]["article_name_internal"]
if this object is String, use eval
to convert the string to a JavaScript object and access the items in the same way with the previous example. 如果此对象是String,则使用eval
将字符串转换为JavaScript对象,并以与前面的示例相同的方式访问项目。
var jsonObject = eval(jsonstring);
jsonObject[2615][0]["article_name_internal"]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.