如何在javascript中访问数组的值

如何在javascript中访问数组的值,javascript,json,titanium,Javascript,Json,Titanium,我正在Tianium Studio中使用Rest api Apigee Baas构建一个Android应用程序 作为后端组件。 我在Apigee Baas中有一些数据,例如:姓名、地址、出勤率等 首先,在我的代码中,我通过以下方式从RESTAPI获得响应 "entities" : [ { "uuid" : "8780273a-d210-11e4-81a4-cba5dc698934", "type" : "attendanc

我正在Tianium Studio中使用Rest api Apigee Baas构建一个Android应用程序 作为后端组件。 我在Apigee Baas中有一些数据,例如:姓名、地址、出勤率等

首先,在我的代码中,我通过以下方式从RESTAPI获得响应

         "entities" : [ {
              "uuid" : "8780273a-d210-11e4-81a4-cba5dc698934",
              "type" : "attendance",
              "created" : 1427192916259,
              "modified" : 1427192916259,
              "attendance" : [ {
              "date" : "10-09-1991",
              "atn" : "0"
     } ],
 "disputes" : "None",
"metadata" : {
"path" : "/attendances/8780273a-d210-11e4-81a4-cba5dc698934"
},
"password" : "1122",
"servicepro" : "pqrst",
"username" : "priyankaa"
} ],//json object response
我在Tianium Studio中尝试了以下代码

index.js file


function doClick(e){
        var url = "api.usergrid.com/PRI_95616/LOGIN/attendances?ql=select * where
        username= '"+$.usertf.value.toString()+"'
        and password='"+$.passtf.value.toString()+"'";

        var client = Ti.Network.createHTTPClient({
        // function called when the response data is available
        onload : function(e) {
        var params={};
        var json=JSON.parse(this.responseText);
        Ti.API.info('resp is'+this.responseText);
        var  user=json.entities[0].username;
        params["username"]=user;
        var pass=json.entities[0].password;         
        params["password"]=pass;
        var servp=json.entities[0].servicepro;         
        params["servicepro"]=servp;
        var atnd=json.entities[0].attendance[0].atn;         
        params["attendance"]=atnd;
        Ti.API.info('atn'+atnd);
        var atndate=json.entities[0].attendance[0].date;         
        params["attendance"]=atndate;
        Ti.API.info('atn'+atndate);

     if((user==$.usertf.value.toString() && pass==$.passtf.value.toString())
     {
        var window = Alloy.createController('profile', params).getView();
        window.open();

     }
     else{
        alert('error');
     };

 },

 onerror : function(e) {
    Ti.API.debug(e.error);
    alert('error');
 },
 timeout : 5000  // in milliseconds
 });
 // Prepare the connection.
 client.open("GET", url);
 // Send the request.
 client.send();//http request
 }

 $.index.open();
这里的Attention是一个包含两个对象atn和date的数组,存储在apigee bass中。 现在我得到了出勤值,但当我通过这个出勤值时,即 使用params将数组连接到另一个控制器,但在那里无法访问该数组。 其他值例如用户名地址被正确访问。只有考勤值不可访问。。 下面是我的profile.js文件。这是我访问这些值的另一个控制器

profile.js 


var args = arguments[0] || {};
$.tff.text=args.username;
$.sertf.text=args.servicepro;
$.prevtf.text=args.attendance[0];
Ti.API.info('ath prof: '+args.attendance.atn);
Ti.API.info('ath date prof: '+args.date);
Ti.API.info('atnd:'+args.attendance[0].atn);
在profile.js中,无法访问阵列考勤。 如何访问这些数组元素 有人能帮我一下吗

您不是从index.js以数组形式发送出席人数,而是试图在profile.js中访问它 如果你愿意改变

var atndate=json.entities[0].attendance[0].date;         
params["attendance"]=atndate;

我想它会起作用的

此外,您正在代码中覆盖参数[Attention]

希望能有帮助

var atndate=json.entities[0].attendance[0];         
params["attendance"]=atndate;