本文整理汇总了Java中org.restlet.ext.json.JsonRepresentation.getJsonObject方法的典型用法代码示例。如果您正苦于以下问题:Java JsonRepresentation.getJsonObject方法的具体用法?Java JsonRepresentation.getJsonObject怎么用?Java JsonRepresentation.getJsonObject使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.restlet.ext.json.JsonRepresentation
的用法示例。
在下文中一共展示了JsonRepresentation.getJsonObject方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: post
import org.restlet.ext.json.JsonRepresentation; //导入方法依赖的package包/类
@Post
public Representation post(JsonRepresentation jsonRep) {
// handle request
JSONObject request = jsonRep.getJsonObject();
String username = request.getString("username");
long userscore = request.getLong("score");
System.out.println(username);
System.out.println(userscore);
Iterator userListIterator = Game.getInstance().getIterator();
while (userListIterator.hasNext()) {
User user = (User) userListIterator.next();
if (user.getUsername().equals(username)) {
user.setScore(userscore);
break;
}
}
// prepare and send response
JSONArray response = new JSONArray(Game.getInstance().getListOfUsers());
return new JsonRepresentation(response);
}
示例2: configure
import org.restlet.ext.json.JsonRepresentation; //导入方法依赖的package包/类
@Post
public void configure(final JsonRepresentation request) {
final ExtensionConfigurationItem item = new ExtensionConfigurationItem(request.getJsonObject());
final ExtensionTokenManager tokenManager = getTokenManager();
if (tokenManager != null) {
tokenManager.setAddresses(item.getHubBaseUrl(), item.getExtensionUrl(), item.getoAuthAuthorizeUrl(),
item.getoAuthTokenUrl());
} else {
getResponse().setStatus(Status.SERVER_ERROR_INTERNAL);
}
}
示例3: post
import org.restlet.ext.json.JsonRepresentation; //导入方法依赖的package包/类
@Post
public Representation post(JsonRepresentation jsonRep) {
JSONObject request = jsonRep.getJsonObject();
String username = request.getString("username");
System.out.println(username);
Iterator userListIterator = Game.getInstance().getIterator();
JSONObject response = new JSONObject();
// check if user already exists
while (userListIterator.hasNext()) {
User user = (User) userListIterator.next();
if (user.getUsername().equals(username)) {
response.put("statusCode", 401);
return new JsonRepresentation(response);
}
}
// otherwise register user
Game.getInstance().addUser(new User(username));
response.put("username", username);
response.put("statusCode", 200);
return new JsonRepresentation(response);
}
示例4: updateFeature
import org.restlet.ext.json.JsonRepresentation; //导入方法依赖的package包/类
@Put
public void updateFeature(JsonRepresentation newFeatureRep) throws JSONException {
// Locate the transaction by its ID
// Locate the feature by its ID
JSONObject json = newFeatureRep.getJsonObject();
}
示例5: processForm
import org.restlet.ext.json.JsonRepresentation; //导入方法依赖的package包/类
/**
* Contract:
* docid optional; 'text' | 'doc-list' required.
* command: cmd=ping sends back a simple response
*
* text = UTF-8 encoded text
* docid = user's provided document ID
* doc-list = An array of text
*
* cmd=ping = report status.
*
* Where json-array contains { docs=[ {docid='A', text='...'}, {docid='B', text='...',...] }
* The entire array must be parsable in memory as a single, traversible JSON object.
* We make no assumption about one-JSON object per line or anything about line-endings as separators.
*
*
* @param params
* the params
* @return the representation
* @throws JSONException
* the JSON exception
*/
@Post("application/json;charset=utf-8")
public Representation processForm(JsonRepresentation params) throws JSONException {
org.json.JSONObject json = params.getJsonObject();
String input = json.optString("text", null);
String docid = json.optString("docid", null);
if (input != null) {
String lang = json.optString("lang", null);
TextInput item = new TextInput(docid, input);
item.langid = lang;
RequestParameters job = fromRequest(json);
return process(item, job);
}
// org.json.JSONArray array = json.optJSONArray("doc-list");
// if (array != null) {
// return processList(array);
// }
return status("FAIL", "Invalid API use text+docid pair or doc-list was not found");
}