这应该相当简单。我有一个名为“库存”的类(class)。我有两个重要的专栏。 “产品名称”和“产品价格”。我需要根据产品名称获取产品价格。我将如何查询名称然后检索相关价格? String 始终返回为 null。
更新:
@Override
public String getCost() {
final String[] productValue = {null};
ParseQuery<ParseObject> query = new ParseQuery<ParseObject>
query.whereEqualTo("productName", Capris);
query.findInBackground(new FindCallback<ParseObject>() {
public void done(List<ParseObject> list, ParseException e) {
if (e == null) { //no exception, hence success
productValue[0] = list.get(0).getString("productPrice");
}
}
});
return productValue[0];
}
这或多或少是我现在所拥有的。有没有更好的方法来返回一个字符串?它仍然返回为空。我只需要从查询中返回值。
有效答案:
Returning String from Parse.com query
这已在另一个问题中解决。在上面的代码中,productValue[0] 可能是空的,因为它是一个 aysnc 调用所以用 find() 替换 findInBackground
最佳答案
productCost
是一类解析对象类型。当您应该访问包含 productValue
的类的成员变量时,您将其转换为字符串。你应该使用这样的东西:
query.findInBackground(new FindCallback() {
@Override
public void done(List<ParseObject> objects,
ParseException e) {
if (e == null) {
for (ParseObject productCost : objects) {
// use productCost.get(' product value columnName') to access the properties of the productCost object.
}
} else {
//Query failed. There is an error
}
}
});
关于java - 从解析表中检索字符串值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33686775/