• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java Gson类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中org.bukkit.craftbukkit.libs.com.google.gson.Gson的典型用法代码示例。如果您正苦于以下问题:Java Gson类的具体用法?Java Gson怎么用?Java Gson使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



Gson类属于org.bukkit.craftbukkit.libs.com.google.gson包,在下文中一共展示了Gson类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: loadJockeyData

import org.bukkit.craftbukkit.libs.com.google.gson.Gson; //导入依赖的package包/类
private void loadJockeyData() {
	File file = new File(this.getDataFolder(), "data.json");
	
	if (!file.exists()) {
		try {
			file.createNewFile();
			InputStream inStream = getResource("data.json");
			OutputStream out = new FileOutputStream(file);
			
			ByteStreams.copy(inStream, out);
			close(inStream);
			close(out);
		} catch (IOException ex) {
			getLogger().log(Level.SEVERE, "Could not load jockey data.", ex);
			return;
		}
	}
	
	try {
		Gson gson = new Gson();
		jockeyDataManager = gson.fromJson(new FileReader(file), JockeyDataManager.class);
	} catch (Exception e) {
		getLogger().log(Level.SEVERE, "Could not load jockey data.", e);
	}
}
 
开发者ID:CodingBadgers,项目名称:MineKart,代码行数:26,代码来源:MineKart.java


示例2: search

import org.bukkit.craftbukkit.libs.com.google.gson.Gson; //导入依赖的package包/类
private String search(String channel, String sender, String login,
		String hostname, String message, String args[], String statement)
		throws Exception {

	Gui.log(new String(new Gson().toJson(new Request(statement, sender))
			.getBytes(), "UTF-8"));

	return PostServer
			.SendPost(
					new String(""),
					new String(
							("https://en.wikipedia.org/w/api.php?action=opensearch&search="
									+ statement + "&limit=1&namespace=0&format=json")
									.getBytes(), "UTF-8"));
}
 
开发者ID:D0048,项目名称:irc-helper,代码行数:16,代码来源:WikiSearchPlugin.java


示例3: toRobot

import org.bukkit.craftbukkit.libs.com.google.gson.Gson; //导入依赖的package包/类
private String toRobot(String channel, String sender, String login,
		String hostname, String message, String args[], String statement)
		throws Exception {

	// StringEntity postingString = new StringEntity(new String(new Gson()
	// .toJson(new Request(statement, sender)).getBytes(), "UTF-8"));

	Gui.log(new String(new Gson().toJson(new Request(statement, sender))
			.getBytes(), "UTF-8"));

	return PostServer.SendPost(
			new String(new Gson().toJson(new Request(statement, sender))
					.getBytes(), "UTF-8"),
			"http://www.tuling123.com/openapi/api").split("\"")[5];
	/*
	 * HttpClient httpClient = HttpClientBuilder.create().build(); HttpPost
	 * post = new HttpPost("http://www.tuling123.com/openapi/api");
	 * post.setEntity(postingString); post.setHeader("Content-type",
	 * "application/json"); post.addHeader("Content-Type", "charset=UTF-8");
	 * 
	 * HttpResponse res = httpClient.execute(post); JSONObject jsonObject =
	 * new JSONObject(); if (res != null) { jsonObject = new
	 * JSONObject(IOUtils.toString(res.getEntity() .getContent(), "UTF-8"));
	 * String text = jsonObject.get("text").toString(); if (text != null) {
	 * // success System.out.println(jsonObject.getString("text")); } else {
	 * throw new Exception("Error #" + jsonObject.get("code") + " " +
	 * jsonObject.get("error_message")); } } return jsonObject.toString();
	 */

	// return in.readLine().split("\"")[5];
	/*
	 * final URL url = new URL("http://www.tuling123.com/openapi/api");
	 * final URLConnection urlConnection = url.openConnection();
	 * urlConnection.setDoOutput(true);
	 * urlConnection.setRequestProperty("Content-Type",
	 * "application/json; charset=utf-8"); urlConnection.connect(); final
	 * OutputStream outputStream = urlConnection.getOutputStream();
	 * outputStream.write(("{\"key\": \"" +
	 * "3aab1c245bb8401fa8a3b3bf1689bc35" + "\"}").getBytes("UTF-8"));
	 * outputStream.write(("{\"info\": \"" + statement + "\"}")
	 * .getBytes("UTF-8")); outputStream.write(("{\"userid\": \"" + sender +
	 * "\"}") .getBytes("UTF-8")); outputStream.flush(); BufferedReader in =
	 * new BufferedReader(new InputStreamReader(
	 * urlConnection.getInputStream())); return
	 * in.readLine().split("\"")[5];
	 */
	/*
	 * String urlString = "http://www.tuling123.com/openapi/api"; HttpClient
	 * httpClient = HttpClientBuilder.create().build(); HttpPost postRequest
	 * = new HttpPost(urlString);
	 * 
	 * // build request parameters StringBody apiKey = new
	 * StringBody("3aab1c245bb8401fa8a3b3bf1689bc35",
	 * ContentType.MULTIPART_FORM_DATA); StringBody info = new
	 * StringBody(statement, ContentType.MULTIPART_FORM_DATA); StringBody
	 * userid = new StringBody(sender, ContentType.MULTIPART_FORM_DATA);
	 * 
	 * MultipartEntityBuilder builder = MultipartEntityBuilder.create();
	 * builder.addPart("key", apiKey); builder.addPart("info", info); //
	 * builder.addPart("userid", userid);
	 * 
	 * postRequest.setEntity(builder.build()); HttpResponse res = null;
	 * 
	 * // execute the request res = httpClient.execute(postRequest);
	 * 
	 * JSONObject jsonObject = new JSONObject(); if (res != null) {
	 * jsonObject = new JSONObject(IOUtils.toString(res.getEntity()
	 * .getContent(), "UTF-8")); String text =
	 * jsonObject.get("text").toString(); if (text != null) { // success
	 * System.out.println(jsonObject.getString("text")); } else { throw new
	 * Exception("Error #" + jsonObject.get("code") + " " +
	 * jsonObject.get("error_message")); } } return jsonObject.toString();
	 */
}
 
开发者ID:D0048,项目名称:irc-helper,代码行数:75,代码来源:TLPlugin.java


示例4: getGson

import org.bukkit.craftbukkit.libs.com.google.gson.Gson; //导入依赖的package包/类
public Gson getGson() {
	return gson;
}
 
开发者ID:ulchm,项目名称:RedisChat,代码行数:4,代码来源:RedisChat.java


示例5: getGson

import org.bukkit.craftbukkit.libs.com.google.gson.Gson; //导入依赖的package包/类
/**
 * Gets gson.
 *
 * @return Value of gson.
 */
public Gson getGson() {
    return gson;
}
 
开发者ID:Relicum,项目名称:Ipsum,代码行数:9,代码来源:PlayerHandler.java


示例6: toJSON

import org.bukkit.craftbukkit.libs.com.google.gson.Gson; //导入依赖的package包/类
/**
 * Returns the object as a Json String.
 *
 * @param gson the gson object to use to convert it to a Json string.
 * @return the Json String
 */
public String toJSON(Gson gson) {

    return gson.toJson(this, Region.class);
}
 
开发者ID:Relicum,项目名称:Ipsum,代码行数:11,代码来源:Region.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java ClientSession类代码示例发布时间:2022-05-23
下一篇:
Java BitmapFontParameter类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap