Package com.restfb.json

Examples of com.restfb.json.JsonArray


    } catch (JsonException e) {
      throw new FacebookJsonMappingException("The connection JSON you provided was invalid: " + json, e);
    }

    // Pull out data
    JsonArray jsonData = jsonObject.getJsonArray("data");
    for (int i = 0; i < jsonData.length(); i++)
      data.add(connectionType.equals(JsonObject.class) ? (T) jsonData.get(i) : facebookClient.getJsonMapper()
        .toJavaObject(jsonData.get(i).toString(), connectionType));

    // Pull out paging info, if present
    if (jsonObject.has("paging")) {
      JsonObject jsonPaging = jsonObject.getJsonObject("paging");
      previousPageUrl = jsonPaging.has("previous") ? jsonPaging.getString("previous") : null;
View Full Code Here


    }

    try {
      List<T> list = new ArrayList<T>();

      JsonArray jsonArray = new JsonArray(json);
      for (int i = 0; i < jsonArray.length(); i++)
        list.add(toJavaObject(jsonArray.get(i).toString(), type));

      return unmodifiableList(list);
    } catch (FacebookJsonMappingException e) {
      throw e;
    } catch (Exception e) {
View Full Code Here

  protected Object toJsonInternal(Object object, boolean ignoreNullValuedProperties) {
    if (object == null)
      return NULL;

    if (object instanceof List<?>) {
      JsonArray jsonArray = new JsonArray();
      for (Object o : (List<?>) object)
        jsonArray.put(toJsonInternal(o, ignoreNullValuedProperties));

      return jsonArray;
    }

    if (object instanceof Map<?, ?>) {
View Full Code Here

            + Comments.class.getSimpleName() + " object instead.  Working around that " + "by coercing into an empty "
            + Comments.class.getSimpleName() + " instance...");

      JsonObject workaroundJsonObject = new JsonObject();
      workaroundJsonObject.put("count", 0);
      workaroundJsonObject.put("data", new JsonArray());
      rawValueAsString = workaroundJsonObject.toString();
    }

    // Some other type - recurse into it
    return toJavaObject(rawValueAsString, type);
View Full Code Here

    }

    JsonObject normalizedJson = new JsonObject();

    try {
      JsonArray jsonArray =
          new JsonArray(makeRequest("fql.multiquery", sessionKey, parameters.toArray(new Parameter[0])));

      for (int i = 0; i < jsonArray.length(); i++) {
        JsonObject jsonObject = jsonArray.getJsonObject(i);

        // For empty resultsets, Facebook will return an empty object instead of
        // an empty list. Hack around that here.
        JsonArray resultsArray =
            jsonObject.get("fql_result_set") instanceof JsonArray ? jsonObject.getJsonArray("fql_result_set")
                : new JsonArray();

        normalizedJson.put(jsonObject.getString("name"), resultsArray);
      }
    } catch (JsonException e) {
      throw new FacebookJsonMappingException("Unable to process fql.multiquery JSON response", e);
View Full Code Here

        throw new IllegalArgumentException("You cannot specify the '" + QUERIES_PARAM_NAME
            + "' URL parameter yourself - " + "RestFB will populate this for you with "
            + "the queries you passed to this method.");

    try {
      JsonArray jsonArray =
          new JsonArray(makeRequest("fql.multiquery", false, false, null,
            parametersWithAdditionalParameter(Parameter.with(QUERIES_PARAM_NAME, queriesToJson(queries)), parameters)));

      JsonObject normalizedJson = new JsonObject();

      for (int i = 0; i < jsonArray.length(); i++) {
        JsonObject jsonObject = jsonArray.getJsonObject(i);

        // For empty resultsets, Facebook will return an empty object instead of
        // an empty list. Hack around that here.
        JsonArray resultsArray =
            jsonObject.get("fql_result_set") instanceof JsonArray ? jsonObject.getJsonArray("fql_result_set")
                : new JsonArray();

        normalizedJson.put(jsonObject.getString("name"), resultsArray);
      }

      return objectType.equals(JsonObject.class) ? (T) normalizedJson : jsonMapper.toJavaObject(
View Full Code Here

      for (int i = 0; i < jsonObjects.size(); i++) {
        JsonObject jsonObject = jsonObjects.get(i);

        // For empty resultsets, Facebook will return an empty object instead of
        // an empty list. Hack around that here.
        JsonArray resultsArray =
            jsonObject.get("fql_result_set") instanceof JsonArray ? jsonObject.getJsonArray("fql_result_set")
                : new JsonArray();

        normalizedJson.put(jsonObject.getString("name"), resultsArray);
      }

      return objectType.equals(JsonObject.class) ? (T) normalizedJson : jsonMapper.toJavaObject(
View Full Code Here

    SortedMap<Date, JsonArray> raw =
        executeInsightQueriesByDate(facebookClient, pageObjectId, metrics, period, periodEndDates);

    if (!raw.isEmpty()) {
      for (Date date : raw.keySet()) {
        JsonArray resultByMetric = raw.get(date);

        // [{"metric":"page_active_users","value":582},
        // {"metric":"page_tab_views_login_top_unique","value":{"wall":12,"app_4949752878":1}}]
        for (int resultIndex = 0; resultIndex < resultByMetric.length(); resultIndex++) {
          JsonObject metricResult = resultByMetric.getJsonObject(resultIndex);

          try {
            String metricName = metricResult.getString("metric");
            Object metricValue = metricResult.get("value");
View Full Code Here

      JsonObject response = facebookClient.executeFqlMultiquery(fqlByQueryIndex, JsonObject.class);

      // transform the response into a Map
      for (Iterator<?> it = response.keys(); it.hasNext();) {
        String key = (String) it.next();
        JsonArray innerResult = (JsonArray) response.get(key);

        try {
          // resolve the map key back into a date
          int queryIndex = Integer.parseInt(key);
          Date d = datesByQueryIndex.get(queryIndex);
View Full Code Here

    JsonObject btaylor = facebookClient.fetchObject("btaylor", JsonObject.class);
    out.println(btaylor.getString("name"));

    JsonObject photosConnection = facebookClient.fetchObject("me/photos", JsonObject.class);
    JsonArray photosConnectionData = photosConnection.getJsonArray("data");

    if (photosConnectionData.length() > 0) {
      String firstPhotoUrl = photosConnectionData.getJsonObject(0).getString("source");
      out.println(firstPhotoUrl);
    }

    String query = "SELECT uid, name FROM user WHERE uid=220439 or uid=7901103";
    List<JsonObject> queryResults = facebookClient.executeQuery(query, JsonObject.class);
View Full Code Here

TOP

Related Classes of com.restfb.json.JsonArray

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.