当前位置: 首页>>代码示例>>Java>>正文


Java JsonObject.toString方法代码示例

本文整理汇总了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";
    }
}
 
开发者ID:qinjr,项目名称:TeamNote,代码行数:25,代码来源:ConvertUtilImpl.java

示例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();
}
 
开发者ID:qinjr,项目名称:TeamNote,代码行数:9,代码来源:CooperateController.java

示例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();
}
 
开发者ID:qinjr,项目名称:TeamNote,代码行数:9,代码来源:LetterController.java

示例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;
}
 
开发者ID:VISNode,项目名称:VISNode,代码行数:8,代码来源:NodeNetworkParser.java

示例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();
}
 
开发者ID:qinjr,项目名称:TeamNote,代码行数:9,代码来源:NoteController.java

示例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.");

}
 
开发者ID:dhaval-mehta,项目名称:url-to-google-drive,代码行数:33,代码来源:DriveUploader.java

示例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();
}
 
开发者ID:qinjr,项目名称:TeamNote,代码行数:9,代码来源:UserController.java

示例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;
}
 
开发者ID:xiaomin0322,项目名称:marathon-auth-plugin,代码行数:66,代码来源:HTTPAuthFilter.java

示例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();
}
 
开发者ID:qinjr,项目名称:TeamNote,代码行数:13,代码来源:EvaluateController.java

示例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();
}
 
开发者ID:qinjr,项目名称:TeamNote,代码行数:12,代码来源:UserController.java

示例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();
}
 
开发者ID:qinjr,项目名称:TeamNote,代码行数:15,代码来源:UserController.java

示例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();
}
 
开发者ID:Sixt,项目名称:ja-micro,代码行数:9,代码来源:JsonRpcRequest.java

示例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();
}
 
开发者ID:qinjr,项目名称:TeamNote,代码行数:14,代码来源:NoteManageServiceImpl.java

示例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();
}
 
开发者ID:qinjr,项目名称:TeamNote,代码行数:10,代码来源:NoteController.java

示例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();
}
 
开发者ID:qinjr,项目名称:TeamNote,代码行数:8,代码来源:EvaluateController.java


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