gpt4 book ai didi

android - 如何从在线数据库kinvey获取数据

转载 作者:行者123 更新时间:2023-11-29 22:40:11 24 4
gpt4 key购买 nike

我正在尝试从在线数据库获取数据,并使用 Textview 在简单的表单上根据今天的日期显示结果。

请参阅下面的代码:

myJavaClient.appData("tdSensorData", Sensor.class).get(new KinveyListCallback<Sensor>() {

@Override
public void onSuccess(Sensor[] result) {

Toast.makeText(MainActivity.this,"Get All Worked!\n Got: " + result.length,Toast.LENGTH_LONG).show();


}

@Override
public void onFailure(Throwable error) {
Toast.makeText(MainActivity.this,
"Get All error: " + error.getMessage(),
Toast.LENGTH_LONG).show();
}

});

问题是当我尝试从名为 Sensor 的实体类获取数据时,当我从 success 方法中输入 result.getSensorr1() 时,我收到错误。任何人都可以帮忙,根据 toast 的 result.length 我得到 4000,这是我从数据库中获得的正确行数

这是我的实体类:

package com.accenture.googleglassaccenture;

import com.google.api.client.json.GenericJson;
import com.google.api.client.util.Key;

public class Sensor extends GenericJson{

@Key("_id")
private String id;

@Key("DATETIME")
private String datetime;

@Key("MAC")
private String mac;

@Key("SENSOR_1")
private String sensorr1;

@Key("SENSOR_2")
private String sensorr2;

@Key("SENSOR_3")
private String sensorr3;

@Key("SENSOR_4")
private String sensorr4;

@Key("TEMP")
private String temp;

@Key("BAT")
private String bat;


public String getId() {
return id;
}



public void setId(String id) {
this.id = id;
}



public String getDatetime() {
return datetime;
}



public void setDatetime(String datetime) {
this.datetime = datetime;
}



public String getMac() {
return mac;
}



public void setMac(String mac) {
this.mac = mac;
}



public String getSensorr1() {
return sensorr1;
}



public void setSensorr1(String sensorr1) {
this.sensorr1 = sensorr1;
}



public String getSensorr2() {
return sensorr2;
}



public void setSensorr2(String sensorr2) {
this.sensorr2 = sensorr2;
}



public String getSensorr3() {
return sensorr3;
}



public void setSensorr3(String sensorr3) {
this.sensorr3 = sensorr3;
}



public String getSensorr4() {
return sensorr4;
}



public void setSensorr4(String sensorr4) {
this.sensorr4 = sensorr4;
}



public String getTemp() {
return temp;
}



public void setTemp(String temp) {
this.temp = temp;
}



public String getBat() {
return bat;
}



public void setBat(String bat) {
this.bat = bat;
}


public Sensor() {
// TODO Auto-generated constructor stub
}
}

这是表格的结果

{"_id":"51a71254d06fdbee04000653","DATETIME":"2013-05-23T11:16:34Z","MAC":"0013a200407e0086","SENSOR_1":"91.19","SENSOR_2":"19.093333333333334","SENSOR_3":"439.3097042968143","SENSOR_4":"0.0","TEMP":"-17","BAT":"47","_acl":{"creator":"kid_VPuam4pfqf"},"_kmd":{"lmt":"2013-05-30T08:48:20.335Z","ect":"2013-05-30T08:48:20.335Z"}},{"_id":"51a71255d06fdbee04000654","DATETIME":"2013-05-23T11:17:33Z","MAC":"0013a200407e0086","SENSOR_1":"91.19","SENSOR_2":"19.093333333333334","SENSOR_3":"494.4776331634671","SENSOR_4":"0.0","TEMP":"-17","BAT":"47","_acl":

最佳答案

您得到的结果是数组的形式。您必须迭代数组并获取实体对象。这是一个例子:

public void onSuccess(Sensor[] result) {
if (result.length != 0) {
for (Sensor sensor:result){
sensor.getSensorr1();
//what-ever-else-you-need
}
}

关于android - 如何从在线数据库kinvey获取数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29401814/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com