當前位置: 首頁>>代碼示例>>Java>>正文


Java JsonArray.add方法代碼示例

本文整理匯總了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;
}
 
開發者ID:DesktopRemoteManagement,項目名稱:DRM-Desktop,代碼行數:22,代碼來源:Message.java

示例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;
}
 
開發者ID:Notoh,項目名稱:DecompiledMinecraft,代碼行數:25,代碼來源:ServerStatusResponse.java

示例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;
}
 
開發者ID:BtoBastian,項目名稱:bStats-Metrics,代碼行數:29,代碼來源:Metrics.java

示例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;
}
 
開發者ID:google,項目名稱:webauthndemo,代碼行數:22,代碼來源:PublicKeyCredentialDescriptor.java

示例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());
    }
}
 
開發者ID:stuebz88,項目名稱:modName,代碼行數:17,代碼來源:BiomeSettings.java

示例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;
}
 
開發者ID:BtoBastian,項目名稱:bStats-Metrics,代碼行數:29,代碼來源:Metrics.java

示例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();
    }
}
 
開發者ID:eltrueno,項目名稱:TruenoNPC,代碼行數:39,代碼來源:TruenoNPC_v1_11_r1.java

示例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;
}
 
開發者ID:marlonwang,項目名稱:raven,代碼行數:10,代碼來源:ServiceHelper.java

示例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;
}
 
開發者ID:graphflow,項目名稱:graphflow,代碼行數:34,代碼來源:Subgraphs.java

示例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;
}
 
開發者ID:Zephery,項目名稱:newblog,代碼行數:12,代碼來源:JMXClient.java

示例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;
}
 
開發者ID:Guichaguri,項目名稱:SkinFixer,代碼行數:38,代碼來源:SkinConfig.java

示例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;
}
 
開發者ID:Gurgy,項目名稱:Cypher,代碼行數:16,代碼來源:ApiMock.java

示例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);
}
 
開發者ID:F1r3w477,項目名稱:CustomWorldGen,代碼行數:16,代碼來源:FMLNetworkHandler.java

示例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;
}
 
開發者ID:beyondeye,項目名稱:kjsonpatch,代碼行數:8,代碼來源:TestDataGenerator.java

示例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;
}
 
開發者ID:CoreXDevelopment,項目名稱:CoreX,代碼行數:9,代碼來源:TimingData.java


注:本文中的com.google.gson.JsonArray.add方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。