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


Java JsonObject.add方法代码示例

本文整理汇总了Java中com.google.gson.JsonObject.add方法的典型用法代码示例。如果您正苦于以下问题:Java JsonObject.add方法的具体用法?Java JsonObject.add怎么用?Java JsonObject.add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.google.gson.JsonObject的用法示例。


在下文中一共展示了JsonObject.add方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: storeCloudItem

import com.google.gson.JsonObject; //导入方法依赖的package包/类
/**
 * Transfers file from a user's cloud "drive" to Filestack.
 *
 * @param providerName one of the static CLOUD constants in this class
 * @param options      storage options for how to save the file in Filestack
 * @return             new filelink
 * @throws HttpException on error response from backend
 * @throws IOException           on network failure
 */
@SuppressWarnings("ConstantConditions")
public FileLink storeCloudItem(String providerName, String path, StorageOptions options)
    throws IOException {

  if (options == null) {
    options = new StorageOptions.Builder().build();
  }

  JsonObject params = makeCloudParams(providerName, path);
  params.add("store", options.getAsJson());
  Response<JsonObject> response = Networking.getCloudService().store(params).execute();
  Util.checkResponseAndThrow(response);
  JsonElement responseJson = response.body().get(providerName);
  Gson gson = new Gson();
  CloudStoreResponse storeInfo = gson.fromJson(responseJson, CloudStoreResponse.class);
  return new FileLink(config, storeInfo.getHandle());
}
 
开发者ID:filestack,项目名称:filestack-java,代码行数:27,代码来源:Client.java

示例2: testAuthenticate

import com.google.gson.JsonObject; //导入方法依赖的package包/类
@Test
public void testAuthenticate() {
    JsonObject payload = new JsonObject();
    payload.addProperty("username", "Notch");
    payload.addProperty("password", "password");

    JsonObject agent = new JsonObject();
    agent.addProperty("name", "Minecraft");
    agent.addProperty("version", 1);

    payload.add("agent", agent);

    CompletableFuture<JsonObject> result = service.authenticate(payload);
    CompletableFuture.allOf(result).join();

    JsonObject object = result.join();
    this.validateAuthenticate(object);
}
 
开发者ID:MPLauncher,项目名称:Yggdrasil,代码行数:19,代码来源:YggdrasilServiceTest.java

示例3: serialize

import com.google.gson.JsonObject; //导入方法依赖的package包/类
public JsonElement serialize(ServerStatusResponse.Players 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:sudofox,项目名称:Backmemed,代码行数:25,代码来源:ServerStatusResponse.java

示例4: getRequestJsonObject

import com.google.gson.JsonObject; //导入方法依赖的package包/类
protected JsonObject getRequestJsonObject(Logger logger, boolean logFailedRequests) {
    JsonObject chart = new JsonObject();
    chart.addProperty("chartId", chartId);
    try {
        JsonObject data = getChartData();
        if (data == null) {
            // If the data is null we don't send the chart.
            return null;
        }
        chart.add("data", data);
    } catch (Throwable t) {
        if (logFailedRequests) {
            logger.log(Level.WARNING, "Failed to get data for custom chart with id " + chartId, t);
        }
        return null;
    }
    return chart;
}
 
开发者ID:EverCraft,项目名称:SayNoToMcLeaks,代码行数:19,代码来源:Metrics.java

示例5: serialize

import com.google.gson.JsonObject; //导入方法依赖的package包/类
public void serialize(JsonObject object, EnchantRandomly functionClazz, JsonSerializationContext serializationContext)
{
    if (!functionClazz.enchantments.isEmpty())
    {
        JsonArray jsonarray = new JsonArray();

        for (Enchantment enchantment : functionClazz.enchantments)
        {
            ResourceLocation resourcelocation = (ResourceLocation)Enchantment.REGISTRY.getNameForObject(enchantment);

            if (resourcelocation == null)
            {
                throw new IllegalArgumentException("Don\'t know how to serialize enchantment " + enchantment);
            }

            jsonarray.add(new JsonPrimitive(resourcelocation.toString()));
        }

        object.add("enchantments", jsonarray);
    }
}
 
开发者ID:sudofox,项目名称:Backmemed,代码行数:22,代码来源:EnchantRandomly.java

示例6: toJson

import com.google.gson.JsonObject; //导入方法依赖的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

示例7: toQCol

import com.google.gson.JsonObject; //导入方法依赖的package包/类
public JsonElement toQCol() {
    JsonObject col = new JsonObject();
    col.add("name", new JsonPrimitive(this.columnName));
    col.add("columns", this.columns);
    if (this.whereExp != null)
        col.add("where", this.whereExp);
    if (this.limit != -1)
        col.add("limit", new JsonPrimitive(this.limit));
    if (this.offset != -1)
        col.add("offset", new JsonPrimitive(this.offset));
    if (this.orderByCols.size() > 0)
        col.add("order_by", this.orderByCols);
    return col;
}
 
开发者ID:adithya321,项目名称:SOS-The-Healthcare-Companion,代码行数:15,代码来源:ArrayRelationship.java

示例8: toJSON

import com.google.gson.JsonObject; //导入方法依赖的package包/类
@Override
public JsonElement toJSON() {
    JsonObject json = super.toJSON().getAsJsonObject();
    
    if (null != title) {
        json.add(TITLE, new JsonPrimitive(title));
    }
    if (null != openPage) {
        json.add(_OPEN_PAGE, new JsonPrimitive(openPage));
    }
    
    return json;
}
 
开发者ID:marlonwang,项目名称:raven,代码行数:14,代码来源:WinphoneNotification.java

示例9: serializeFeedbackData

import com.google.gson.JsonObject; //导入方法依赖的package包/类
private void serializeFeedbackData(NavigationFeedbackEvent src, JsonSerializationContext context,
                                   JsonObject feedbackEvent) {
  JsonObject feedbackData = context.serialize(src.getFeedbackData()).getAsJsonObject();
  for (Map.Entry<String, JsonElement> e : feedbackData.entrySet()) {
    feedbackEvent.add(e.getKey(), e.getValue());
  }
}
 
开发者ID:mapbox,项目名称:mapbox-events-android,代码行数:8,代码来源:FeedbackEventSerializer.java

示例10: serialize

import com.google.gson.JsonObject; //导入方法依赖的package包/类
@Override
public void serialize(JsonObject object, RandomWeaponFunction functionClazz,
		JsonSerializationContext serializationContext) {
	object.add("upgrade_range", serializationContext.serialize(functionClazz.upgradeRange));
	object.add("valve_chance", serializationContext.serialize(functionClazz.valveWepChance));
	// object.add("possibleValues",
	// serializationContext.serialize(functionClazz.possibleValues));
	// object.add("data",
	// serializationContext.serialize(functionClazz.metaRange));
}
 
开发者ID:rafradek,项目名称:Mods,代码行数:11,代码来源:RandomWeaponFunction.java

示例11: sendCustomMessage

import com.google.gson.JsonObject; //导入方法依赖的package包/类
public void sendCustomMessage(UserSession userSession, SocketMessageDTO message) throws IOException {
	Object outputData = message.getData();
	JsonObject jsonMessage = new JsonObject();
	jsonMessage.addProperty("type", message.getType());
	if(outputData != null) {
		if(outputData instanceof JsonObject) {
			jsonMessage.add("data", (JsonObject) outputData);
		} else {
			JsonElement data = gson.toJsonTree(outputData);
			jsonMessage.add("data", data);
		}
	}
	sendMessage(userSession, jsonMessage);
}
 
开发者ID:zralock,项目名称:CTUConference,代码行数:15,代码来源:MessageSenderImpl.java

示例12: submitData

import com.google.gson.JsonObject; //导入方法依赖的package包/类
/**
 * Collects the data and sends it afterwards.
 */
private void submitData() {
    final JsonObject data = getServerData();

    final JsonArray pluginData = new JsonArray();
    // Search for all other bStats Metrics classes to get their plugin data
    for (Object metrics : knownMetricsInstances) {
        try {
            Object plugin = metrics.getClass().getMethod("getPluginData").invoke(metrics);
            if (plugin instanceof JsonObject) {
                pluginData.add((JsonObject) plugin);
            }
        } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException ignored) { }
    }

    data.add("plugins", pluginData);

    try {
        // Send the data
        sendData(data);
    } catch (Exception e) {
        // Something went wrong! :(
        if (logFailedRequests) {
            plugin.getLogger().log(Level.WARNING, "Could not submit plugin stats!", e);
        }
    }
}
 
开发者ID:BtoBastian,项目名称:bStats-Metrics,代码行数:30,代码来源:MetricsLite.java

示例13: cacheSkin

import com.google.gson.JsonObject; //导入方法依赖的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_8_r3.java

示例14: qrCodeCreateTmpTicket

import com.google.gson.JsonObject; //导入方法依赖的package包/类
@Override
public WxMpQrCodeTicket qrCodeCreateTmpTicket(int sceneId, Integer expireSeconds) throws WxErrorException {
  if (sceneId == 0) {
    throw new WxErrorException(WxError.newBuilder().setErrorCode(-1).setErrorMsg("临时二维码场景值不能为0!").build());
  }

  //expireSeconds 该二维码有效时间,以秒为单位。 最大不超过2592000(即30天),此字段如果不填,则默认有效期为30秒。
  if (expireSeconds != null && expireSeconds > 2592000) {
    throw new WxErrorException(WxError.newBuilder().setErrorCode(-1)
      .setErrorMsg("临时二维码有效时间最大不能超过2592000(即30天)!").build());
  }

  if (expireSeconds == null) {
    expireSeconds = 30;
  }

  String url = API_URL_PREFIX + "/create";
  JsonObject json = new JsonObject();
  json.addProperty("action_name", "QR_SCENE");
  if (expireSeconds != null) {
    json.addProperty("expire_seconds", expireSeconds);
  }
  JsonObject actionInfo = new JsonObject();
  JsonObject scene = new JsonObject();
  scene.addProperty("scene_id", sceneId);
  actionInfo.add("scene", scene);
  json.add("action_info", actionInfo);
  String responseContent = this.wxMpService.post(url, json.toString());
  return WxMpQrCodeTicket.fromJson(responseContent);
}
 
开发者ID:11590692,项目名称:Wechat-Group,代码行数:31,代码来源:WxMpQrcodeServiceImpl.java

示例15: serialize

import com.google.gson.JsonObject; //导入方法依赖的package包/类
@Override
public JsonElement serialize(final Recipe recipe, final Type type, final JsonSerializationContext context) {

    Preconditions.checkNotNull(recipe);
    Preconditions.checkNotNull(type);
    Preconditions.checkNotNull(context);

    final JsonObject jsonObject = new JsonObject();

    jsonObject.add("name", context.serialize(recipe.name));
    jsonObject.addProperty("url", recipe.url.toString());
    jsonObject.add("versions", context.serialize(recipe.versions));

    return jsonObject;
}
 
开发者ID:LoopPerfect,项目名称:buckaroo,代码行数:16,代码来源:RecipeSerializer.java


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