本文整理汇总了Java中com.restfb.json.JsonObject.put方法的典型用法代码示例。如果您正苦于以下问题:Java JsonObject.put方法的具体用法?Java JsonObject.put怎么用?Java JsonObject.put使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.restfb.json.JsonObject
的用法示例。
在下文中一共展示了JsonObject.put方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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));
}
示例2: 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();
}
示例3: 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));
}
示例4: executeMultiquery
import com.restfb.json.JsonObject; //导入方法依赖的package包/类
/**
* @see com.restfb.LegacyFacebookClient#executeMultiquery(java.util.Map, java.lang.String, java.lang.Class,
* com.restfb.Parameter[])
*/
@Override
public <T> T executeMultiquery(Map<String, String> queries, String sessionKey, Class<T> resultType,
Parameter... additionalParameters) {
List<Parameter> parameters = new ArrayList<Parameter>();
parameters.add(Parameter.with("queries", queriesToJson(queries)));
for (Parameter additionalParameter : additionalParameters) {
if (additionalParameter.name.equals("queries"))
throw new IllegalArgumentException("You cannot specify a parameter named 'queries' "
+ "because it's reserved for use by RestFB for this call. "
+ "Specify your queries in the Map that gets passed to this method.");
parameters.add(additionalParameter);
}
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);
}
return jsonMapper.toJavaObject(normalizedJson.toString(), resultType);
}
示例5: executeMultiquery
import com.restfb.json.JsonObject; //导入方法依赖的package包/类
/**
* @see com.restfb.FacebookClient#executeMultiquery(java.util.Map, java.lang.Class, com.restfb.Parameter[])
*/
@SuppressWarnings("unchecked")
public <T> T executeMultiquery(Map<String, String> queries, Class<T> objectType, Parameter... parameters) {
verifyParameterPresence("objectType", objectType);
for (Parameter parameter : parameters)
if (QUERIES_PARAM_NAME.equals(parameter.name))
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(
normalizedJson.toString(), objectType);
} catch (JsonException e) {
throw new FacebookJsonMappingException("Unable to process fql.multiquery JSON response", e);
}
}
示例6: getMovies
import com.restfb.json.JsonObject; //导入方法依赖的package包/类
@GET
@Path("movies/{id}")
@Produces(MediaType.APPLICATION_JSON)
public static String getMovies(@PathParam("id") String userId) {
Logger.getLogger(XPostWS.class.getName()).log(Level.INFO, "retrieving movies for " + userId);
final JsonObject result = new JsonObject();
Mongo mongo = getActionMongo();
final DB db = mongo.getDB("mydb");
final DBCollection moviesCol = db.getCollection("movies");
String map = "function () {" + "if (this.userId != this.friendId)" + "{emit(this.id, this);}" + "};";
String reduce = "function (key, values) {" +
"var res = {};" +
"res.name = values[0].name;" +
"res.id = key;" +
"res.userId = values[0].userId;" +
"res.poster = values[0].poster;" +
"res.rating = values[0].rating;" +
"res.imdbId = values[0].imdbId;" +
"res.friendId = [];" +
"for (var i = 0; i<values.length; ++i) {" +
"res.friendId.push(String(values[i].friendId));" +
"}" +
"return res;}";
final BasicDBObject searchObject = new BasicDBObject("userId", userId);
MapReduceCommand mapReduceComand = new MapReduceCommand(moviesCol, map, reduce, null,
MapReduceCommand.OutputType.INLINE, searchObject);
final MapReduceOutput moviesReduced = moviesCol.mapReduce(mapReduceComand);
JsonArray moviesInfo = new JsonArray();
for (DBObject movie : moviesReduced.results()) {
moviesInfo.put(new JsonObject(movie.toString()));
}
Logger.getLogger(XPostWS.class.getName()).log(Level.INFO,
"retrieved " + moviesInfo.length() + " movies for user " + userId);
if (moviesInfo.length() == 0) {
result.put("movies", new JsonArray().toString());
} else {
sortMovies(moviesInfo, userId);
result.put("movies", moviesInfo);
}
try {
return new String(result.toString().getBytes("UTF-8"));
} catch (UnsupportedEncodingException e) {
Logger.getLogger(TAG).severe(e.getMessage());
return result.toString();
}
}
示例7: executeFqlMultiquery
import com.restfb.json.JsonObject; //导入方法依赖的package包/类
/**
* @see com.restfb.FacebookClient#executeFqlMultiquery(java.util.Map, java.lang.Class, com.restfb.Parameter[])
*/
@Override
@SuppressWarnings("unchecked")
public <T> T executeFqlMultiquery(Map<String, String> queries, Class<T> objectType, Parameter... parameters) {
verifyParameterPresence("objectType", objectType);
for (Parameter parameter : parameters)
if (FQL_QUERY_PARAM_NAME.equals(parameter.name))
throw new IllegalArgumentException("You cannot specify the '" + FQL_QUERY_PARAM_NAME
+ "' URL parameter yourself - " + "RestFB will populate this for you with "
+ "the queries you passed to this method.");
try {
List<JsonObject> jsonObjects =
jsonMapper.toJavaList(
makeRequest(
"fql",
false,
false,
null,
parametersWithAdditionalParameter(Parameter.with(FQL_QUERY_PARAM_NAME, queriesToJson(queries)),
parameters)), JsonObject.class);
JsonObject normalizedJson = new JsonObject();
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(
normalizedJson.toString(), objectType);
} catch (JsonException e) {
throw new FacebookJsonMappingException("Unable to process fql.multiquery JSON response", e);
}
}