本文整理汇总了Java中com.google.gson.JsonObject.toString方法的典型用法代码示例。如果您正苦于以下问题:Java JsonObject.toString方法的具体用法?Java JsonObject.toString怎么用?Java JsonObject.toString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.gson.JsonObject
的用法示例。
在下文中一共展示了JsonObject.toString方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: formMessage
import com.google.gson.JsonObject; //导入方法依赖的package包/类
public String formMessage(String content) {
try {
JsonObject contentObj = new JsonParser().parse(content).getAsJsonObject();
int userId = contentObj.get("uid").getAsInt();
String datetime = contentObj.get("datetime").getAsString();
SimpleDateFormat insdf = new SimpleDateFormat("EEE MMM dd HH:mm:ss zzz yyyy", Locale.US);
SimpleDateFormat outsdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String parsedDatetime = outsdf.format(insdf.parse(datetime));
String chatContent = contentObj.get("content").getAsString();
String username = userDao.getUserById(userId).getUsername();
String avatar = userDao.getUserById(userId).getAvatar();
JsonObject messageJson = new JsonObject();
messageJson.addProperty("uid", userId);
messageJson.addProperty("username", username);
messageJson.addProperty("datetime", parsedDatetime);
messageJson.addProperty("avatar", avatar);
messageJson.addProperty("content", chatContent);
return messageJson.toString();
} catch (ParseException e) {
e.printStackTrace();
return "error";
}
}
示例2: ignoreSuggestion
import com.google.gson.JsonObject; //导入方法依赖的package包/类
@RequestMapping("/ignoreSuggestion")
@ResponseBody
public String ignoreSuggestion(@RequestParam(value = "suggestionId") int suggestionId) {
cooperateService.ignoreSuggestion(suggestionId);
JsonObject json = new JsonObject();
json.addProperty("result", "success");
return json.toString();
}
示例3: getSentLetters
import com.google.gson.JsonObject; //导入方法依赖的package包/类
@RequestMapping("/letter/getSentLetters")
@ResponseBody
public String getSentLetters() {
int userId = getUserId();
JsonObject json = new JsonObject();
json.addProperty("letterSent", letterService.getAllSentLetters(userId));
return json.toString();
}
示例4: get
import com.google.gson.JsonObject; //导入方法依赖的package包/类
private JsonElement get(final JsonObject wrapper, String memberName) {
final JsonElement elem = wrapper.get(memberName);
if (elem == null) {
throw new JsonParseException("no '" + memberName + "' member found in what was expected to be an interface wrapper: " + wrapper.toString());
}
return elem;
}
示例5: changeVersion
import com.google.gson.JsonObject; //导入方法依赖的package包/类
@RequestMapping(value = "/changeVersion")
@ResponseBody
public String changeVersion(@RequestParam(value = "noteId") int noteId, @RequestParam(value = "versionPointer") int versionPointer) {
noteManageService.changeVersion(noteId, versionPointer);
JsonObject json = new JsonObject();
json.addProperty("result", "success");
return json.toString();
}
示例6: obtainUploadUrl
import com.google.gson.JsonObject; //导入方法依赖的package包/类
private void obtainUploadUrl() throws IOException {
user.refreshTokenIfNecessary();
HttpURLConnection connection = (HttpURLConnection) CREATE_FILE_URL.openConnection();
connection.setRequestMethod("POST");
connection.setRequestProperty("User-Agent", USER_AGENT);
JsonObject jsonObject = new JsonObject();
jsonObject.addProperty("name", downloadFileInfo.getFileName());
String postBody = jsonObject.toString();
connection.setDoOutput(true);
connection.setRequestProperty("Content-Type", "application/json");
connection.setRequestProperty("Authorization",
user.getToken().getTokenType() + " " + user.getToken().getAccessToken());
connection.setRequestProperty("X-Upload-Content-Type", downloadFileInfo.getContentType());
connection.setRequestProperty("X-Upload-Content-Length", String.valueOf(downloadFileInfo.getContentLength()));
try (PrintStream writer = new PrintStream(connection.getOutputStream())) {
writer.print(postBody);
}
connection.connect();
int statusCode = connection.getResponseCode();
if (statusCode == HttpStatus.OK.value())
createdFileUrl = new URL(connection.getHeaderField("Location"));
else if (statusCode == HttpStatus.UNAUTHORIZED.value())
throw new ApiException(HttpStatus.UNAUTHORIZED, "Your session is expired");
else
throw new ApiException(HttpStatus.INTERNAL_SERVER_ERROR, "Cannot create new file in google dirve.");
}
示例7: unfollowTag
import com.google.gson.JsonObject; //导入方法依赖的package包/类
@RequestMapping("/unfollowTag")
@ResponseBody
public String unfollowTag(@RequestParam("tagId") int tagId){
userBasicService.unfollowTag(getUserId(), tagId);
JsonObject json = new JsonObject();
json.addProperty("result", "success");
return json.toString();
}
示例8: filterGroups
import com.google.gson.JsonObject; //导入方法依赖的package包/类
public byte[] filterGroups(HttpServletRequest request, byte[] content) {
byte[] newContent = content;
if (ArrayUtils.isEmpty(newContent)) {
return newContent;
}
try {
String method = request.getMethod();
String uri = request.getRequestURI();
String queryString = request.getQueryString();
String path = uri + "?" + queryString;
String url = AuthUtil.QUERY_GROUP_URI;
if (AuthUtil.HTTP_GET.equalsIgnoreCase(method) && path.equalsIgnoreCase(url)) {
String umContent = MessageGZIP.uncompressToString(newContent);
User user = AuthUtil.THREAD_LOCAL_USER.get();
if (user == null) {
log.warn("AuthUtil.THREAD_LOCAL_USER.get()");
return null;
}
JsonObject jsonObject = new JsonParser().parse(umContent)
.getAsJsonObject();
// 新的jsonArrayGroups
JsonArray newJsonArrayGroups = new JsonArray();
JsonArray jsonArrayGroups = jsonObject.getAsJsonArray("groups");
log.info("jsonArrayGroups.size >>>>>{}", jsonArrayGroups.size());
if (!jsonArrayGroups.isJsonNull()) {
for (JsonElement jsonElement : jsonArrayGroups) {
JsonObject jsonObjectGroup = jsonElement
.getAsJsonObject();
String id = jsonObjectGroup.get("id").getAsString();
Permission permission = AuthUtil
.getQueryPermission(user);
log.info(" path >>>>>> {} permission >>>> {}", id,permission);
if (permission != null) {
String queryPath = permission.getOn();
// 判断分组查询权限
if ("/".equals(queryPath) || queryPath.contains(id)) {
newJsonArrayGroups.add(jsonElement);
}
}
}
}
jsonObject.remove("groups");
jsonObject.add("groups", newJsonArrayGroups);
String newContentStr = jsonObject.toString();
newContent = MessageGZIP.compressToByte(newContentStr);
log.info("newJsonArrayGroups.size >>>>>{}", newJsonArrayGroups.size());
}
} catch (Exception e) {
log.error(e.getMessage(), e);
}
return newContent;
}
示例9: star
import com.google.gson.JsonObject; //导入方法依赖的package包/类
@RequestMapping("/evaluate/star")
@ResponseBody
public String star(@RequestParam("notebookId") int notebookId) {
int userId = getUserId();
JsonObject json = new JsonObject();
if (evaluateService.star(userId, notebookId) == 1) {
json.addProperty("result", "success");
} else {
json.addProperty("result", "failed");
}
return json.toString();
}
示例10: updateUserProfile
import com.google.gson.JsonObject; //导入方法依赖的package包/类
@RequestMapping("/updateUserProfile")
@ResponseBody
public String updateUserProfile(@RequestParam("email") String email, @RequestParam("phone") String phone,
@RequestParam("ps") String ps) {
int userId = getUserId();
userBasicService.updateUserProfile(userId, email, phone, ps);
JsonObject json = new JsonObject();
json.addProperty("result", "success");
return json.toString();
}
示例11: loginUserDetail
import com.google.gson.JsonObject; //导入方法依赖的package包/类
@RequestMapping("/loginUserDetail")
@ResponseBody
public String loginUserDetail() {
int userId = getUserId();
User user = userBasicService.getUserById(userId);
UserInfo userInfo = userBasicService.getUserInfoByUsername(user.getUsername());
String userString = new Gson().toJson(user);
String userInfoString = new Gson().toJson(userInfo);
JsonObject json = new JsonObject();
json.addProperty("userInfo", userInfoString);
json.addProperty("user", userString);
return json.toString();
}
示例12: toString
import com.google.gson.JsonObject; //导入方法依赖的package包/类
@Override
public String toString() {
JsonObject json = new JsonObject();
json.add(ID_FIELD, id);
json.addProperty(METHOD_FIELD, method);
json.add(PARAMS_FIELD, params);
return json.toString();
}
示例13: getNoteDetail
import com.google.gson.JsonObject; //导入方法依赖的package包/类
public String getNoteDetail(int noteId, int userId) {
Note note = noteDao.getNoteById(noteId);
JsonObject json = new JsonParser().parse(new Gson().toJson(note)).getAsJsonObject();
if (note.getUpvoters().contains(userId)) {
json.addProperty("evaluate", 1);
} else if (note.getDownvoters().contains(userId)) {
json.addProperty("evaluate", 2);
} else {
json.addProperty("evaluate", 3);
}
return json.toString();
}
示例14: collectNotebook
import com.google.gson.JsonObject; //导入方法依赖的package包/类
@RequestMapping(value = "/collectNotebook")
@ResponseBody
public String collectNotebook(@RequestParam("notebookId") int notebookId) {
int userId = getUserId();
noteManageService.collectNotebook(userId, notebookId);
JsonObject json = new JsonObject();
json.addProperty("result", "success");
return json.toString();
}
示例15: reward
import com.google.gson.JsonObject; //导入方法依赖的package包/类
@RequestMapping("/evaluate/reward")
@ResponseBody
public String reward(@RequestParam("noteId") int noteId) {
JsonObject json = new JsonObject();
json.addProperty("qrcode", evaluateService.reward(noteId));
return json.toString();
}