【问题标题】:Parse.com: retrieve JSONArray and JSONObject from serverParse.com:从服务器检索 JSONArray 和 JSONObject
【发布时间】:2014-10-29 05:25:40
【问题描述】:

我一直在我的 android 应用程序中使用 Parse.com db,在过去的几个小时里我似乎无法通过这个错误。

我想要的只是从 Parse.com 检索 JSONObject 和 JSONArray,但我不断收到“illegalStateException”,我不知道为什么。我到处看了看,我不知道我做错了什么。

这是我创建的 JSONObejct:(数组也是如此,但我会为您省去麻烦):

JSONObject x = new JSONObject();
    try {
        x.put("col_1" ,23.234);
        x.put("col_2" ,14.34);

    } catch (JSONException e) {

        Log.e("JSON_CREATION", e.getMessage());
    }
    newClient.put("fff", x); // This is a ParseObject ojbect, which I later save using 
                             // saveInBackground()  (and also tried with 'save()'

上面的代码完美运行,我还在 Parse.Com 中检查了确实保存了一个具有这些特定值的新对象。

现在我只需要重新获取这些数据。我就是这样做的:

**JSONObject a = newClient.getJSONObject("fff");** // This line throws 'illegalStateException'
    try {
        double b = a.getDouble("col_1");
    } catch (JSONException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

希望有任何帮助。

【问题讨论】:

  • 查看解析文档的“获取对象”部分。查看文档中的解析查询。然后查看您的语句“getJSONObj ...”.. 调用解析查询以响应 JSON 对象而不是您所拥有的
  • 您能详细说明一下吗?我已经有了查询应该返回的 parseObject。我的问题是我无法检索其中一个 JSONObject 字段,谢谢!

标签: android parse-platform arrays illegalstateexception jsonobject


【解决方案1】:

解决了。

我持有的 ParseObject 的实例似乎不是最新的(我以为我以前获取过它)。

解决方案是调用 x.fetch() / x.fetchInBackground() / x.fetchIfNeededInBackground() 等。 我不需要运行查询,因为正如我所说的 - 我持有这个对象的一个​​实例。

希望对您有所帮助。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多