• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java JsonObject类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中com.restfb.json.JsonObject的典型用法代码示例。如果您正苦于以下问题:Java JsonObject类的具体用法?Java JsonObject怎么用?Java JsonObject使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



JsonObject类属于com.restfb.json包,在下文中一共展示了JsonObject类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: fetchObjectsAsJsonObject

import com.restfb.json.JsonObject; //导入依赖的package包/类
void fetchObjectsAsJsonObject() {
  out.println("* Fetching multiple objects at once as a JsonObject *");

  List<String> ids = new ArrayList<String>();
  ids.add("4");
  ids.add("http://www.imdb.com/title/tt0117500/");

  // Make the API call
  JsonObject results = facebookClient25.fetchObjects(ids, JsonObject.class);

  System.out.println(results.toString());

  // Pull out JSON data by key and map each type by hand.
  JsonMapper jsonMapper = new DefaultJsonMapper();
  User user = jsonMapper.toJavaObject(results.getString("4","{}"), User.class);
  Url url = jsonMapper.toJavaObject(results.get("http://www.imdb.com/title/tt0117500/").toString(), Url.class);

  out.println("User is " + user);
  out.println("URL is " + url);
}
 
开发者ID:restfb,项目名称:restfb-examples,代码行数:21,代码来源:GraphReaderExample.java


示例2: reader

import com.restfb.json.JsonObject; //导入依赖的package包/类
@GET
@Path("/reader")
@Produces(MediaType.APPLICATION_JSON)
public String reader(@Context HttpServletRequest req, @QueryParam("showUnreadOnly") boolean unreadOnly,
        @QueryParam("sortByAlphabet") int sortAz, @QueryParam("sortByUnread") int sortUnread) {
    long userId = Session.getUserId(req.getSession());
    long profileId = Session.getProfileId(req.getSession());
    if (userId == 0 || profileId == 0) {
        return JSONErrorMsgs.getAccessDenied();
    }

    JsonObject obj = new JsonObject();
    obj.put(JSONFields.BOOL_SHOW_UNREAD_ONLY, unreadOnly);
    obj.put(JSONFields.INT_SORT_AZ, sortAz);
    obj.put(JSONFields.INT_SORT_UNREAD, sortUnread);

    return JSONUtils.count(UserKeyValuesTable.save(userId, profileId, UserKeyValuesTable.READER_SETTINGS_KEY, obj));
}
 
开发者ID:sliechti,项目名称:feedrdr,代码行数:19,代码来源:UserSettings.java


示例3: onResponse

import com.restfb.json.JsonObject; //导入依赖的package包/类
@Override
public boolean onResponse(String response)
{
    JsonObject o = new JsonObject(response);

    try
    {
        email = o.getString("email");
        name = o.getString("name");
        locale = o.getString("locale");
    } 
    catch (Exception e) {
        return false;
    }         
    
    return true;
}
 
开发者ID:sliechti,项目名称:feedrdr,代码行数:18,代码来源:GoogleOAuthProvider.java


示例4: onResponse

import com.restfb.json.JsonObject; //导入依赖的package包/类
@Override
public boolean onResponse(String response)
{
    JsonObject o = new JsonObject(response);

    name = "Live-Account";
    email = "";
    locale = "en_US";

    try
    {
        email = o.getJsonObject("emails").getString("preferred");
        name = o.getString("name");
        locale = o.getString("locale");
    } 
    catch (Exception e) {
        return false;
    }
    
    return true;
}
 
开发者ID:sliechti,项目名称:feedrdr,代码行数:22,代码来源:WindowsLiveOAuthProvider.java


示例5: save

import com.restfb.json.JsonObject; //导入依赖的package包/类
public static int save(long userId, long profileId, int key, JsonObject obj) {
    try (Connection conn = Database.getConnection()){
        String query = String.format("UPDATE %s SET %s = '%s' WHERE %s = %d AND %s = %d AND %s = %d", TABLE,
                DBFields.STR_KEY_VALUE, SQLUtils.asSafeString(obj.toString()), DBFields.LONG_PROFILE_ID, profileId,
                DBFields.LONG_USER_ID, userId, DBFields.INT_KEY_NAME, key);
        if (conn.createStatement().executeUpdate(query) == 0) {
            query = String.format("INSERT INTO %s (%s, %s, %s, %s) VALUES (%d, %d, %d, '%s')", TABLE,
                    DBFields.LONG_USER_ID, DBFields.LONG_PROFILE_ID, DBFields.INT_KEY_NAME, DBFields.STR_KEY_VALUE,
                    userId, profileId, key, SQLUtils.asSafeString(obj.toString()));
            conn.createStatement().execute(query);
        }

        return 1;
    } catch (SQLException ex) {
        logger.error("save {}/{}/{} failed {}", ex, userId, profileId, key, ex.getMessage());
    }

    return -1;
}
 
开发者ID:sliechti,项目名称:feedrdr,代码行数:20,代码来源:UserKeyValuesTable.java


示例6: get

import com.restfb.json.JsonObject; //导入依赖的package包/类
/**
 * @param retDefault
 */
public static JsonObject get(long userId, long profileId, int key, boolean retDefault) {
    JsonObject o = get(userId, profileId, key);

    if (o.length() == 0) {
        switch (key) {
        case READER_SETTINGS_KEY:
            return defaultReader;

        case VIEW_ALL_SETTINGS:
        case VIEW_SAVED_SETTINGS:
        case VIEW_RECENTLY_READ_SETTINGS:
            return defaultGenericSettings;
        }
    }

    return o;
}
 
开发者ID:sliechti,项目名称:feedrdr,代码行数:21,代码来源:UserKeyValuesTable.java


示例7: getFriends

import com.restfb.json.JsonObject; //导入依赖的package包/类
/**
 * Return list of friends based on list of given ids
 *
 * @param idsOfFriendsToDisplay of friends, which we want to obtain from facebook
 * @return list of friends
 */
public List<FacebookUserBean> getFriends(final List<String> idsOfFriendsToDisplay) throws IOException, PortletException {
    List<FacebookUserBean> fbFriends = new ArrayList<FacebookUserBean>();

    // Render friends with their pictures
    if (idsOfFriendsToDisplay.size() > 0) {
        // Fetch all required friends with obtained ids
        JsonObject friendsResult = this.fetchObjects(idsOfFriendsToDisplay, JsonObject.class,
            Parameter.with("fields", "id,name,picture"));

        if (friendsResult == null) {
            return fbFriends;
        }

        for (String id : idsOfFriendsToDisplay) {
            JsonObject current = friendsResult.getJsonObject(id);
            UserWithPicture friend = facebookClient.getJsonMapper().toJavaObject(current.toString(), UserWithPicture.class);
            fbFriends.add(new FacebookUserBean(friend));
        }
    }

    return fbFriends;
}
 
开发者ID:exo-samples,项目名称:docs-samples,代码行数:29,代码来源:FacebookClientWrapper.java


示例8: findMaxMovieIndex

import com.restfb.json.JsonObject; //导入依赖的package包/类
private static int findMaxMovieIndex(final JsonArray array, int start) {
    double maxValue = 0;
    int result = start;

    for (int i = start; i < array.length(); ++i) {
        final JsonObject current = array.getJsonObject(i);
        final JsonObject values = current.getJsonObject("value");
        double imdbRating = 0;
        double friendRating = 0;
        try {
            friendRating = Double.parseDouble(values.getString("friendRating"));
            imdbRating = Double.parseDouble(values.getString("rating"));
        } catch (Exception e) {
        }
        final double rating = imdbRating + friendRating;
        if (rating > maxValue) {
            maxValue = rating;
            result = i;
        }
    }

    return result;
}
 
开发者ID:milenchechev,项目名称:RecommendedStream,代码行数:24,代码来源:XPostWS.java


示例9: fetchObjectsAsJsonObject

import com.restfb.json.JsonObject; //导入依赖的package包/类
void fetchObjectsAsJsonObject() {
  out.println("* Fetching multiple objects at once as a JsonObject *");

  List<String> ids = new ArrayList<String>();
  ids.add("btaylor");
  ids.add("http://www.imdb.com/title/tt0117500/");

  // Make the API call
  JsonObject results = facebookClient.fetchObjects(ids, JsonObject.class);

  // Pull out JSON data by key and map each type by hand.
  JsonMapper jsonMapper = new DefaultJsonMapper();
  User user = jsonMapper.toJavaObject(results.getString("btaylor"), User.class);
  Url url = jsonMapper.toJavaObject(results.getString("http://www.imdb.com/title/tt0117500/"), Url.class);

  out.println("User is " + user);
  out.println("URL is " + url);
}
 
开发者ID:oleke,项目名称:Gender-Mining,代码行数:19,代码来源:GraphReaderExample.java


示例10: fetchDifferentDataTypesAsJsonObject

import com.restfb.json.JsonObject; //导入依赖的package包/类
void fetchDifferentDataTypesAsJsonObject() {
  out.println("* Fetching different types of data as JsonObject *");

  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);

  if (queryResults.size() > 0)
    out.println(queryResults.get(0).getString("name"));
}
 
开发者ID:oleke,项目名称:Gender-Mining,代码行数:21,代码来源:GraphReaderExample.java


示例11: queriesToJson

import com.restfb.json.JsonObject; //导入依赖的package包/类
/**
 * Given a map of query names to queries, verify that it contains valid data and convert it to a JSON object string.
 * 
 * @param queries
 *          The query map to convert.
 * @return The {@code queries} in JSON string format.
 * @throws IllegalArgumentException
 *           If the provided {@code queries} are invalid.
 */
protected String queriesToJson(Map<String, String> queries) {
  verifyParameterPresence("queries", queries);

  if (queries.keySet().size() == 0)
    throw new IllegalArgumentException("You must specify at least one query.");

  JsonObject jsonObject = new JsonObject();

  for (Entry<String, String> entry : queries.entrySet()) {
    if (isBlank(entry.getKey()) || isBlank(entry.getValue()))
      throw new IllegalArgumentException("Provided queries must have non-blank keys and values. " + "You provided: "
          + queries);

    try {
      jsonObject.put(trimToEmpty(entry.getKey()), trimToEmpty(entry.getValue()));
    } catch (JsonException e) {
      // Shouldn't happen unless bizarre input is provided
      throw new IllegalArgumentException("Unable to convert " + queries + " to JSON.", e);
    }
  }

  return jsonObject.toString();
}
 
开发者ID:oleke,项目名称:Gender-Mining,代码行数:33,代码来源:BaseFacebookClient.java


示例12: getScopes

import com.restfb.json.JsonObject; //导入依赖的package包/类
static List<String> getScopes() {
    
    ArrayList<String> scopes = new ArrayList();
    
    JsonObject permResponse = facebookClient.fetchObject("me/permissions", JsonObject.class);
    JsonArray permsArray = permResponse.getJsonArray("data");
    for (int i = 0; i < permsArray.length(); i++) {
        
        JsonObject perm = permsArray.getJsonObject(i);
        if(perm.getString("status").equals("granted")){
            scopes.add(perm.getString("permission"));
        }
    }
    
    return scopes;
}
 
开发者ID:wandora-team,项目名称:wandora,代码行数:17,代码来源:AbstractFBGraphExtractor.java


示例13: fetchDifferentDataTypesAsJsonObject

import com.restfb.json.JsonObject; //导入依赖的package包/类
void fetchDifferentDataTypesAsJsonObject() {
  out.println("* Fetching different types of data as JsonObject *");

  JsonObject zuck = facebookClient25.fetchObject("4", JsonObject.class);
  out.println(zuck.get("name").toString());

  JsonObject photosConnection = facebookClient25.fetchObject("me/photos", JsonObject.class);
  JsonArray photosConnectionData = photosConnection.get("data").asArray();

  if (photosConnectionData.size() > 0) {
    String firstPhotoUrl = photosConnectionData.get(0).asObject().getString("source",null);
    out.println(firstPhotoUrl);
  }
}
 
开发者ID:restfb,项目名称:restfb-examples,代码行数:15,代码来源:GraphReaderExample.java


示例14: modules

import com.restfb.json.JsonObject; //导入依赖的package包/类
@GET
@Path("/modules")
@Produces(MediaType.APPLICATION_JSON)
public String modules(@Context HttpServletRequest req, @QueryParam("tmpl") String tmpl,
        @QueryParam("v") int viewMode) {
    long userId = Session.getUserId(req.getSession());
    long profileId = Session.getProfileId(req.getSession());
    if (userId == 0 || profileId == 0) {
        return JSONErrorMsgs.getAccessDenied();
    }

    int k = -1;
    switch (tmpl) {
    case "saved":
        k = UserKeyValuesTable.VIEW_SAVED_SETTINGS;
        break;

    case "all":
        k = UserKeyValuesTable.VIEW_ALL_SETTINGS;
        break;

    case "rr":
        k = UserKeyValuesTable.VIEW_RECENTLY_READ_SETTINGS;
        break;

    default:
        return JSONErrorMsgs.getErrorParams();
    }

    JsonObject obj = new JsonObject();
    obj.put(JSONFields.INT_VIEW_MODE, viewMode);

    return JSONUtils.count(UserKeyValuesTable.save(userId, profileId, k, obj));
}
 
开发者ID:sliechti,项目名称:feedrdr,代码行数:35,代码来源:UserSettings.java


示例15: onResponse

import com.restfb.json.JsonObject; //导入依赖的package包/类
@Override
public boolean onResponse(String response) {
    JsonObject o = new JsonObject(response);

    try {
        email = o.getString("email");
        name = o.getString("name");
        locale = o.getString("locale");
    } catch (Exception e) {
        return false;
    }

    return true;
}
 
开发者ID:sliechti,项目名称:feedrdr,代码行数:15,代码来源:FacebookOAuthProvider.java


示例16: fetchSources

import com.restfb.json.JsonObject; //导入依赖的package包/类
/*******************************************
 * Fetching sources
 */

@Override
public void fetchSources() {

    FacebookClient facebookClient =
            new DefaultFacebookClient(this.token, Version.VERSION_2_8);

    JsonObject jsonSource = facebookClient.fetchObject(this.value, JsonObject.class,
            Parameter.with("fields", "" +
                    "picture, " +
                    "id, " +
                    "name"));

    String name = jsonSource.getString("name");
    String imageURL = jsonSource.getJsonObject("picture")
            .getJsonObject("data")
            .getString("url");

    Source source = new Source();

    source.setType("facebook");

    source.setKey(this.key);
    source.setName(name);
    source.setValue(this.value);
    source.setUrlImage(imageURL);
    if (this.sourceDao.isExisting(this.key)) {

        this.sourceDao.update(source);
    } else {
        this.sourceDao.add(source);
    }

}
 
开发者ID:ApplETS,项目名称:applets-java-api,代码行数:38,代码来源:FacebookNewsFetcher.java


示例17: run

import com.restfb.json.JsonObject; //导入依赖的package包/类
@Override
protected Try<User> run() throws Exception {
    DefaultFacebookClient fb = new DefaultFacebookClient(accessToken, Version.VERSION_2_4);

    return Try.of(() -> fb.fetchObject("me", JsonObject.class))
            .map(this::createUser);
}
 
开发者ID:cdelmas,项目名称:microservices-comparison,代码行数:8,代码来源:FacebookAccessTokenVerificationCommand.java


示例18: sort

import com.restfb.json.JsonObject; //导入依赖的package包/类
private static void sort(final JsonArray array) {
    for (int i = 0; i < array.length(); ++i) {
        final JsonObject current = array.getJsonObject(i);
        final int minIndex = findMaxIndex(array, i);
        final JsonObject minObject = array.getJsonObject(minIndex);
        array.put(i, minObject);
        array.put(minIndex, current);
    }
}
 
开发者ID:milenchechev,项目名称:RecommendedStream,代码行数:10,代码来源:XPostWS.java


示例19: findMaxIndex

import com.restfb.json.JsonObject; //导入依赖的package包/类
private static int findMaxIndex(final JsonArray array, int start) {
    double maxValue = Double.MIN_VALUE;
    int result = start;

    for (int i = start; i < array.length(); ++i) {
        final JsonObject current = array.getJsonObject(i);
        if (current.getDouble("value") > maxValue) {
            maxValue = current.getDouble("value");
            result = i;
        }
    }

    return result;
}
 
开发者ID:milenchechev,项目名称:RecommendedStream,代码行数:15,代码来源:XPostWS.java


示例20: executeInsightQueriesByMetricByDate1

import com.restfb.json.JsonObject; //导入依赖的package包/类
@Test
public void executeInsightQueriesByMetricByDate1() throws IOException {
  // note that the query that is passed to the FacebookClient WebRequestor is
  // ignored,
  // so arguments of executeInsightQueriesByDate:
  // (String pageObjectId, Set<String> metrics, Period period)
  // are effectively ignored. In this test we are validating the
  // WebRequestor's json
  // is properly processed
  SortedMap<String, SortedMap<Date, Object>> results =
      executeInsightQueriesByMetricByDate(createFixedResponseFacebookClient("multiResponse_2metrics_1date.json"),
        TEST_PAGE_OBJECT, toStringSet("page_fans", "page_fans_gender"), Period.DAY,
        Collections.singleton(d20101205_0000pst));
  Assert.assertNotNull(results);
  assertEquals(2, results.size());

  SortedMap<Date, Object> metricResult = results.get("page_fans");
  assertEquals(1, metricResult.size());
  assertEquals(3777, metricResult.get(d20101205_0000pst));

  metricResult = results.get("page_fans_gender");
  assertEquals(1, metricResult.size());
  Object metricValue = metricResult.get(d20101205_0000pst);
  Assert.assertTrue(metricValue instanceof JsonObject);
  JsonObject o = (JsonObject) metricValue;
  assertEquals(58, o.getInt("U"));
  assertEquals(1656, o.getInt("F"));
  assertEquals(2014, o.getInt("M"));
}
 
开发者ID:oleke,项目名称:Gender-Mining,代码行数:30,代码来源:InsightUtilsTest.java



注:本文中的com.restfb.json.JsonObject类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java ActionCallback类代码示例发布时间:2022-05-22
下一篇:
Java BeanDefinitionParsingException类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap