java - 从解析表中检索字符串值

标签 java android parse-platform

这应该相当简单。我有一个名为“库存”的类(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/

相关文章:

java - 使用 Apache Tika 从文本/PDF 中删除特殊字符

java - 二维数组越界异常

java - 为什么我的 SQL create 语句导致我的应用程序崩溃?

java - Android 中 String 中的两个(或多个)连续换行符

android - 底部 AppBar 两侧都有图标

parse-platform - 高效查询方式

arrays - 以错误的顺序在 block 内循环附加到数组 - Swift 2.0

xcode - Swift + Parse : 'Can' t use nil for keys or values on PFObject. 使用 NSNull 作为值。

java - 应用程序退出时如何结束非守护线程?

java - Apache Commons IO 文件监控与 JDK WatchService