[英]specific index of a json object
How do I make an array of 3 selected elements of a json object so far: Json object returned from mysql, php into an array of arrays tested true as array 到目前为止,我该如何制作一个由json对象的3个选定元素组成的数组:从mysql,php返回的Json对象到测试为true的数组数组中
var json = $.parseJSON(data);
$(json).each(function(i,val)
{
$.each(val,function(k,v)
{
console.log(k+" : "+ v);
console displays 控制台显示
0 : 2013-03-28 20:18:05 0:2013-03-28 20:18:05
1 : THE MURC THEATRE 1:MURC剧院
2 : COMEDY 2:喜剧
3 : -37.001732 3:-37.001732
4 : 174.789467 4:174.789467
5 : -36.998543 5:-36.998543
6 : 174.787339 6:174.787339
7 : 47 7:47
8 : 1 8:1
9 : 9 9:9
10 : 0.00 10:0.00
11 : 1.00 11:1.00
0 : 2013-03-28 20:18:05 0:2013-03-28 20:18:05
1 : DOWNTOWN THEATRE 1:市区剧院
2 : DRAMA etc etc 2:DRAMA等
Assuming php gave these numbers as keys, when i try to reference them using alert (data.'3'[4]); 假设php将这些数字作为键,当我尝试使用alert(data.'3'[4])引用它们时; or alert (data.3[4]);
或警报(data.3 [4]); I get unexpected number/unexpected string errors.
我收到意外的数字/意外的字符串错误。 I just want the 1st 3rd and 4th items from each iteration to be stored in a variable, how do I reference this ?
我只希望将每次迭代的第1个第3个和第4个项目存储在变量中,该如何引用呢?
data.'3'[4]
and data.3[4]
are both invalid JavaScript syntax. data.'3'[4]
和data.3[4]
都是无效的JavaScript语法。 The correct syntax is still data[3][4]
(or perhaps more accurately data["3"][4]
. You can use bracket notation to access object members even if the keys are numeric. 正确的语法仍然是
data[3][4]
(或更准确地说是data["3"][4]
。即使键是数字,也可以使用方括号表示法访问对象成员。
You are dealing with a multidimensional array structure: 您正在处理多维数组结构:
data[x][y]
Replace x
and y
with desired indexes. 用所需的索引替换
x
和y
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.