【问题标题】:Google+ API ItemScope getRatingValue returns null stringGoogle+ API ItemScope getRatingValue 返回空字符串
【发布时间】:2013-12-14 17:25:24
【问题描述】:

在我使用 Google+ API 的 android 应用中,我可以使用以下代码编写“ReviewActivity”类型的时刻:

ItemScope rating = new ItemScope.Builder()
            .setType("http://schema.org/Rating")
            .setRatingValue(Float.toString(oeuvre.getRating()))
            .setBestRating("5").setWorstRating("0").build();
ItemScope result = new ItemScope.Builder()
            .setType("http://schema.org/Review").setName(titre)
            .setUrl(urlfreebase)
            .setDescription(oeuvre.getNomPeintre()).setReviewRating(rating)
            .build();
ItemScope target = new ItemScope.Builder().setUrl(urlfreebase).build();
Moment moment = new Moment.Builder()
            .setType("http://schemas.google.com/ReviewActivity")
            .setTarget(target).setResult(result).build();
if (monPlusClient.isConnected()) {
    monPlusClient.writeMoment(moment);
}

它的作品,我可以用我的桌面在我的 Google+ 个人资料中阅读它们。

当我加载时刻,在我的应用程序开始时,我也能够读取我的时刻,但我无法获得用户选择的评分值。

在我的听众中:

public void onMomentsLoaded(ConnectionResult status,
        MomentBuffer momentBuffer, String nextPageToken, String updated) {
...
}

我收到了这个目标:

{"description":"Pablo Picasso","url":"https:\/\/developers.google.com\/+\/web\/snippet\/examples\/review","id":"https:\/\/developers.google.com\/+\/web\/snippet\/examples\/review","reviewRating":{"ratingValue":"4.0","worstRating":"0","bestRating":"5"},"name":"Le Pigeon aux petits pois"}

如您所见,评分设置正确:

"reviewRating":{"ratingValue":"4.0","worstRating":"0","bestRating":"5"}

但是当我尝试通过 API 阅读它时:

ItemScope res = m.getResult();
String titre = res.getName();
String desc = res.getDescription();
String streval = res.getRatingValue();

字符串 streval 始终为空

【问题讨论】:

    标签: android google-api google-plus


    【解决方案1】:

    我通过使用 JSON 字符串解决了这个问题:

    ItemScope res = m.getResult();
    String titre = res.getName();
    String desc = res.getDescription();
    try {
        JSONObject jres = new JSONObject(res.toString());
        JSONObject jeval = jres.getJSONObject("reviewRating");
        String streval = jeval.getString("ratingValue");
    } catch (JSONException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-06-14
      • 2020-01-27
      • 2020-07-11
      • 2015-05-25
      • 2011-05-09
      • 1970-01-01
      • 2012-07-20
      相关资源
      最近更新 更多