使用parse.com for android - 查询数组

时间:2013-12-27 10:26:13

标签: android arrays parse-platform

我希望可以在这里问一下。我没有成功从我提出的查询中获取数据。

(我编辑我的代码以使用JSONArray)

这是我的代码:

    int myNumber = 42;
    String myString = "hellol";


    JSONArray myArray = new JSONArray();
    myArray.put(myString);
    myArray.put(myNumber);

    ParseObject bigObject = new ParseObject("BigObject");
    bigObject.put("myNumber", myNumber);
    bigObject.put("myString", myString);
    bigObject.put("myArray", myArray);
    bigObject.put("myNull", JSONObject.NULL);
    bigObject.saveInBackground();

    ParseQuery<ParseObject> query = ParseQuery.getQuery("BigObject");
    query.whereEqualTo("myNumber", myNumber);
    query.getFirstInBackground(new GetCallback<ParseObject>() {
      public void done(ParseObject object, ParseException e) {
        if (object == null) {
             Log.d("score", " not Retrieved the object.");
             toast("null");
        } else {
          Log.d("score", "Retrieved the object.");
          try {
            toast(""+(object.getJSONArray("myArray").get(0)));
        } catch (JSONException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        }
        }
      }
    });

它告诉我&#34; null&#34;在吐司..

我还有更多问题:

2维数组怎么样 - 如何将int [] []添加到数据库?

https://parse.com/docs/android_guide#objects-saving

2 个答案:

答案 0 :(得分:0)

试试这个:

query.whereEqualTo("myString","hellol");

答案 1 :(得分:0)

像这样获取你的ObjectId:

 ParseQuery<ParseObject> query = ParseQuery.getQuery("BigObject");

 query.getInBackground(bigObject.getObjectId, new GetCallback<ParseObject>() {
 public void done(ParseObject object, ParseException e) {
     if (e == null) {
         objectWasRetrievedSuccessfully(object);
     } else {
         objectRetrievalFailed();
     }
 }
}

在二维情况下将其设为数组。