本文整理汇总了Java中com.restfb.json.JsonObject类的典型用法代码示例。如果您正苦于以下问题:Java JsonObject类的具体用法?Java JsonObject怎么用?Java JsonObject使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
JsonObject类属于com.restfb.json包,在下文中一共展示了JsonObject类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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);
}
示例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));
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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);
}
示例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"));
}
示例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();
}
示例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;
}
示例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);
}
}
示例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));
}
示例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;
}