本文整理汇总了Java中com.google.gson.JsonArray.add方法的典型用法代码示例。如果您正苦于以下问题:Java JsonArray.add方法的具体用法?Java JsonArray.add怎么用?Java JsonArray.add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.gson.JsonArray
的用法示例。
在下文中一共展示了JsonArray.add方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: toJson
import com.google.gson.JsonArray; //导入方法依赖的package包/类
public JsonObject toJson(){
JsonObject obj = new JsonObject();
JsonObject message = new JsonObject();
message.addProperty("action", action);
JsonArray pr = new JsonArray();
for (String key : params.keySet()) {
pr.add(params.get(key).toJson());
}
message.add("params", pr);
obj.add("message", message);
if(this.destination != null) {
obj.addProperty("destination", this.destination);
}
obj.addProperty("id", this.id.toString());
return obj;
}
示例2: serialize
import com.google.gson.JsonArray; //导入方法依赖的package包/类
public JsonElement serialize(ServerStatusResponse.PlayerCountData p_serialize_1_, Type p_serialize_2_, JsonSerializationContext p_serialize_3_)
{
JsonObject jsonobject = new JsonObject();
jsonobject.addProperty("max", (Number)Integer.valueOf(p_serialize_1_.getMaxPlayers()));
jsonobject.addProperty("online", (Number)Integer.valueOf(p_serialize_1_.getOnlinePlayerCount()));
if (p_serialize_1_.getPlayers() != null && p_serialize_1_.getPlayers().length > 0)
{
JsonArray jsonarray = new JsonArray();
for (int i = 0; i < p_serialize_1_.getPlayers().length; ++i)
{
JsonObject jsonobject1 = new JsonObject();
UUID uuid = p_serialize_1_.getPlayers()[i].getId();
jsonobject1.addProperty("id", uuid == null ? "" : uuid.toString());
jsonobject1.addProperty("name", p_serialize_1_.getPlayers()[i].getName());
jsonarray.add(jsonobject1);
}
jsonobject.add("sample", jsonarray);
}
return jsonobject;
}
示例3: getPluginData
import com.google.gson.JsonArray; //导入方法依赖的package包/类
/**
* Gets the plugin specific data.
* This method is called using Reflection.
*
* @return The plugin specific data.
*/
public JsonObject getPluginData() {
JsonObject data = new JsonObject();
String pluginName = plugin.getName();
String pluginVersion = plugin.getVersion().orElse("unknown");
data.addProperty("pluginName", pluginName);
data.addProperty("pluginVersion", pluginVersion);
JsonArray customCharts = new JsonArray();
for (CustomChart customChart : charts) {
// Add the data of the custom charts
JsonObject chart = customChart.getRequestJsonObject(logger, logFailedRequests);
if (chart == null) { // If the chart is null, we skip it
continue;
}
customCharts.add(chart);
}
data.add("customCharts", customCharts);
return data;
}
示例4: getJsonObject
import com.google.gson.JsonArray; //导入方法依赖的package包/类
/**
* @return Encoded JsonObject representation of PublicKeyCredentialDescriptor
*/
public JsonObject getJsonObject() {
JsonObject result = new JsonObject();
result.addProperty("type", type.toString());
result.addProperty("id", BaseEncoding.base64().encode(id));
JsonArray transports = new JsonArray();
if (this.transports != null) {
for (AuthenticatorTransport t : this.transports) {
JsonPrimitive element = new JsonPrimitive(t.toString());
transports.add(element);
}
if (transports.size() > 0) {
result.add("transports", transports);
}
}
return result;
}
示例5: writeGroupedEntryMap
import com.google.gson.JsonArray; //导入方法依赖的package包/类
protected static <T extends GroupedBiomeEntry> void writeGroupedEntryMap(JsonObject o, LinkedHashMap<String, T> list) {
for (T biome : list.values()) {
String catname = biome.category.toString();
if (!o.has(catname)) {
o.add(catname, new JsonObject());
}
JsonObject catobject = JsonUtil.getAsObject(o, catname);
if (!catobject.has(biome.group)) {
catobject.add(biome.group, new JsonArray());
}
JsonArray groupobject = JsonUtil.getAsArray(catobject, biome.group);
groupobject.add(biome.toJson());
}
}
示例6: getChartData
import com.google.gson.JsonArray; //导入方法依赖的package包/类
@Override
protected JsonObject getChartData() throws Exception {
JsonObject data = new JsonObject();
JsonObject values = new JsonObject();
Map<String, int[]> map = callable.call();
if (map == null || map.isEmpty()) {
// Null = skip the chart
return null;
}
boolean allSkipped = true;
for (Map.Entry<String, int[]> entry : map.entrySet()) {
if (entry.getValue().length == 0) {
continue; // Skip this invalid
}
allSkipped = false;
JsonArray categoryValues = new JsonArray();
for (int categoryValue : entry.getValue()) {
categoryValues.add(new JsonPrimitive(categoryValue));
}
values.add(entry.getKey(), categoryValues);
}
if (allSkipped) {
// Null = skip the chart
return null;
}
data.add("values", values);
return data;
}
示例7: cacheSkin
import com.google.gson.JsonArray; //导入方法依赖的package包/类
private void cacheSkin(SkinData skindata){
JsonObject jsonFile = getChacheFile(plugin);
JsonArray newskindata = new JsonArray();
if(jsonFile!=null){
JsonArray oldskindata = jsonFile.getAsJsonArray("skindata");
Iterator it = oldskindata.iterator();
while(it.hasNext()){
JsonElement element = (JsonElement) it.next();
if(element.getAsJsonObject().get("id").getAsInt()==this.npcid){
// element.getAsJsonObject().remove("value");
//element.getAsJsonObject().remove("signature");
//element.getAsJsonObject().addProperty("value", skindata.getValue());
//element.getAsJsonObject().addProperty("signature", skindata.getSignature());
}else {
newskindata.add(element);
}
}
}
JsonObject skin = new JsonObject();
skin.addProperty("id", this.npcid);
skin.addProperty("value", skindata.getValue());
skin.addProperty("signature", skindata.getSignature());
newskindata.add(skin);
JsonObject obj = new JsonObject();
obj.add("skindata", newskindata);
try {
plugin.getDataFolder().mkdir();
File file = new File(plugin.getDataFolder().getPath()+"/truenonpcdata.json");
file.createNewFile();
FileWriter writer = new FileWriter(file);
writer.write(obj.toString());
writer.close();
} catch (Exception e) {
e.printStackTrace();
}
}
示例8: fromSet
import com.google.gson.JsonArray; //导入方法依赖的package包/类
public static JsonArray fromSet(Set<String> sets) {
JsonArray array = new JsonArray();
if (null != sets && sets.size() > 0) {
for (String item : sets) {
array.add(new JsonPrimitive(item));
}
}
return array;
}
示例9: toJson
import com.google.gson.JsonArray; //导入方法依赖的package包/类
@Override
public JsonObject toJson() {
JsonObject vertexMap = new JsonObject();
for (String variable : variableIndices.keySet()) {
vertexMap.addProperty(variable, variableIndices.get(variable));
}
JsonObject vertexData = new JsonObject();
for (int vertexId : vertices.keySet()) {
vertexData.add(String.valueOf(vertexId), vertices.get(vertexId).toJson());
}
JsonObject edgeData = new JsonObject();
for (long edgeId : edges.keySet()) {
edgeData.add(String.valueOf(edgeId), edges.get(edgeId).toJson());
}
JsonArray subgraphsResult = new JsonArray();
for (Subgraph subgraph : subgraphs) {
subgraphsResult.add(subgraph.toJson());
}
JsonObject result = new JsonObject();
result.addProperty(JsonKeyConstants.RESPONSE_TYPE.toString(),
ResultType.SUBGRAPHS.toString());
result.add(JsonKeyConstants.VERTEX_MAP.toString(), vertexMap);
result.add(JsonKeyConstants.VERTICES.toString(), vertexData);
result.add(JsonKeyConstants.EDGES.toString(), edgeData);
result.add(JsonKeyConstants.SUBGRAPHS.toString(), subgraphsResult);
addExecutionTimeToJson(result);
return result;
}
示例10: getMemoryPoolDetail
import com.google.gson.JsonArray; //导入方法依赖的package包/类
public JsonArray getMemoryPoolDetail() {
List<MemoryPoolMXBean> mps = ManagementFactory.getMemoryPoolMXBeans();
JsonArray array = new JsonArray();
for (MemoryPoolMXBean mp : mps) {
if (mp.getName().contains("Eden") || mp.getName().contains("Survivor") //win与linux上的不同,顾使用contains
|| mp.getName().contains("Tenured") || mp.getName().contains("Old")) {
array.add(getMpJsonObject(mp));
}
}
return array;
}
示例11: toJson
import com.google.gson.JsonArray; //导入方法依赖的package包/类
public JsonElement toJson(String uuid, String username, String skinUrl, String capeUrl) {
// Lets add all the information in case the game really needs them
JsonObject tex = new JsonObject();
if(skinUrl != null && !skinUrl.isEmpty()) {
JsonObject skin = new JsonObject();
skin.addProperty("url", skinUrl);
tex.add("SKIN", skin);
}
if(capeUrl != null && !capeUrl.isEmpty()) {
JsonObject cape = new JsonObject();
cape.addProperty("url", capeUrl);
tex.add("CAPE", cape);
}
JsonObject textures = new JsonObject();
textures.addProperty("timestamp", (int)(System.currentTimeMillis() / 1000L));
textures.addProperty("profileId", uuid);
textures.addProperty("profileName", username);
textures.add("textures", tex);
JsonObject property = new JsonObject();
property.addProperty("name", "textures");
property.addProperty("value", DatatypeConverter.printBase64Binary(textures.toString().getBytes()));
JsonArray properties = new JsonArray();
properties.add(property);
JsonObject obj = new JsonObject();
obj.addProperty("id", uuid);
obj.addProperty("name", username);
obj.add("properties", properties);
return obj;
}
示例12: getNewAccountData
import com.google.gson.JsonArray; //导入方法依赖的package包/类
private JsonObject getNewAccountData() {
JsonObject data = new JsonObject();
JsonArray events = new JsonArray();
JsonObject event = new JsonObject();
JsonObject settings = new JsonObject();
settings.addProperty("shouldBeTrue", false);
event.addProperty("type", "ex.example.test");
event.add("content", settings);
events.add(event);
data.add("events", events);
return data;
}
示例13: enhanceStatusQuery
import com.google.gson.JsonArray; //导入方法依赖的package包/类
public static void enhanceStatusQuery(JsonObject jsonobject)
{
JsonObject fmlData = new JsonObject();
fmlData.addProperty("type", "FML");
JsonArray modList = new JsonArray();
for (ModContainer mc : Loader.instance().getActiveModList())
{
JsonObject modData = new JsonObject();
modData.addProperty("modid", mc.getModId());
modData.addProperty("version", mc.getVersion());
modList.add(modData);
}
fmlData.add("modList", modList);
jsonobject.add("modinfo", fmlData);
}
示例14: getArrayNode
import com.google.gson.JsonArray; //导入方法依赖的package包/类
private static JsonArray getArrayNode(List<String> args) {
JsonArray countryNode = new JsonArray();
for(String arg : args){
countryNode.add(arg);
}
return countryNode;
}
示例15: export
import com.google.gson.JsonArray; //导入方法依赖的package包/类
JsonArray export() {
JsonArray json = JsonUtil.toArray(this.id, this.count, this.totalTime);
if (this.lagCount > 0) {
json.add(this.lagCount);
json.add(this.lagTotalTime);
}
return json;
}