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


Java JsonObject.addProperty方法代碼示例

本文整理匯總了Java中com.google.gson.JsonObject.addProperty方法的典型用法代碼示例。如果您正苦於以下問題:Java JsonObject.addProperty方法的具體用法?Java JsonObject.addProperty怎麽用?Java JsonObject.addProperty使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.google.gson.JsonObject的用法示例。


在下文中一共展示了JsonObject.addProperty方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: overrideDefaultSettings

import com.google.gson.JsonObject; //導入方法依賴的package包/類
/**
 * Overrides default setting with the settings fetched fron the community.
 *
 * @param clientSettings    Local settings to be used.
 * @param serverSettingJson Settings received from community.
 */
private static void overrideDefaultSettings(JsonObject clientSettings, JsonObject serverSettingJson) {
    if (serverSettingJson != null && !serverSettingJson.isJsonNull()) {
        if (serverSettingJson.has("response_limit")) {
            int limit = serverSettingJson.get("response_limit").getAsInt();
            clientSettings.addProperty("limit", limit);
        }

        if (serverSettingJson.has("discussion_style")) {
            JsonArray discussionStyleArr = serverSettingJson.get("discussion_style").getAsJsonArray();
            StringBuilder conversationStyleSB = new StringBuilder();
            boolean isFirst = true;
            conversationStyleSB.append("(");
            for (JsonElement styleElem : discussionStyleArr) {
                if (isFirst) {
                    isFirst = false;
                } else {
                    conversationStyleSB.append(", ");
                }
                conversationStyleSB.append("'").append(styleElem.getAsString()).append("'");
            }
            conversationStyleSB.append(")");
            if (clientSettings.has("whereClauses")) {
                JsonArray whereArr = clientSettings.get("whereClauses").getAsJsonArray();
                for (JsonElement whereElem : whereArr) {
                    JsonObject whereObj = whereElem.getAsJsonObject();
                    if (whereObj.has("key")) {
                        String key = whereObj.get("key").getAsString();
                        if (key.equals("conversation.style")) {
                            whereObj.addProperty("value", conversationStyleSB.toString());
                        }
                    }
                }
            }
        }
    }
}
 
開發者ID:lithiumtech,項目名稱:li-android-sdk-core,代碼行數:43,代碼來源:LiQueryBuilder.java

示例2: getRequestJsonObject

import com.google.gson.JsonObject; //導入方法依賴的package包/類
private 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.warn("Failed to get data for custom chart with id {}", chartId, t);
        }
        return null;
    }
    return chart;
}
 
開發者ID:codeHusky,項目名稱:HuskyCrates-Sponge,代碼行數:19,代碼來源:Metrics.java

示例3: testUpdateGroupChat

import com.google.gson.JsonObject; //導入方法依賴的package包/類
@Test
public void testUpdateGroupChat() {
    JsonObject json = new JsonObject();
    json.addProperty("userId", 1);
    json.addProperty("datetime", new Date().toString());
    json.addProperty("content", "haha");
    ArrayList<String> chats = new ArrayList<String>();
    chats.add(json.toString());
    GroupChat groupChat = new GroupChat(1, chats);

    groupChatDao.addGroupChat(groupChat);
    groupChat = groupChatDao.getAllGroupChats().get(0);
    ArrayList<String> newList = new ArrayList<String>();
    newList.add("hhh");
    groupChat.setContents(newList);
    groupChatDao.updateGroupChat(groupChat);

    Assert.assertEquals(groupChatDao.getAllGroupChats().get(0).getContents(), newList);

    groupChatDao.deleteGroupChat(groupChat);
}
 
開發者ID:qinjr,項目名稱:TeamNote,代碼行數:22,代碼來源:GroupChatDaoImplTest.java

示例4: writeObservationsToJSON

import com.google.gson.JsonObject; //導入方法依賴的package包/類
@Override
public void writeObservationsToJSON(JsonObject json, MissionInit missionInit)
{
	// Return a string that is unique for every cell on the x/z plane (ignores y)
	EntityPlayerSP player = Minecraft.getMinecraft().thePlayer;
	// getPosition() rounds to int.
	int x = player.getPosition().getX();
	int z = player.getPosition().getZ();
	json.addProperty("cell", "(" + x + "," + z + ")");
}
 
開發者ID:Yarichi,項目名稱:Proyecto-DASI,代碼行數:11,代碼來源:ObservationFromDiscreteCellImplementation.java

示例5: addAggStdInfo

import com.google.gson.JsonObject; //導入方法依賴的package包/類
private static void addAggStdInfo(JsonObject jo, List<JsonObject> samples) {
    // beginMsec, endMsec, nSamples
    long msec = samples.get(0).get(KEY_TS).getAsLong();
    long msec2 = samples.get(samples.size()-1).get(KEY_TS).getAsLong();
    int nSamples = samples.size();
    
    jo.addProperty(KEY_TS, msec2);
    jo.addProperty(KEY_AGG_BEGIN_TS, msec);
    jo.addProperty(KEY_AGG_COUNT, nSamples);
}
 
開發者ID:osswangxining,項目名稱:iot-edge-greengrass,代碼行數:11,代碼來源:JsonTuples.java

示例6: banNote

import com.google.gson.JsonObject; //導入方法依賴的package包/類
@RequestMapping("/banNote")
@ResponseBody
public String banNote(@RequestParam("verifyId") int verifyId) {
    adminService.banNote(verifyId);
    JsonObject obj = new JsonObject();
    obj.addProperty("result","success");
    return new Gson().toJson(obj);
}
 
開發者ID:qinjr,項目名稱:TeamNote,代碼行數:9,代碼來源:AdminController.java

示例7: onSerialization

import com.google.gson.JsonObject; //導入方法依賴的package包/類
protected void onSerialization(JsonObject data)
{
    if (this.getValue() != null)
    {
        data.addProperty("uuid", ((GameProfile)this.getValue()).getId() == null ? "" : ((GameProfile)this.getValue()).getId().toString());
        data.addProperty("name", ((GameProfile)this.getValue()).getName());
        super.onSerialization(data);
        data.addProperty("level", (Number)Integer.valueOf(this.permissionLevel));
        data.addProperty("bypassesPlayerLimit", Boolean.valueOf(this.bypassesPlayerLimit));
    }
}
 
開發者ID:sudofox,項目名稱:Backmemed,代碼行數:12,代碼來源:UserListOpsEntry.java

示例8: tagCreate

import com.google.gson.JsonObject; //導入方法依賴的package包/類
@Override
public WxUserTag tagCreate(String name) throws WxErrorException {
  String url = API_URL_PREFIX + "/create";
  JsonObject json = new JsonObject();
  JsonObject tagJson = new JsonObject();
  tagJson.addProperty("name", name);
  json.add("tag", tagJson);

  String responseContent = this.wxMpService.post(url, json.toString());
  return WxUserTag.fromJson(responseContent);
}
 
開發者ID:11590692,項目名稱:Wechat-Group,代碼行數:12,代碼來源:WxMpUserTagServiceImpl.java

示例9: onSerialization

import com.google.gson.JsonObject; //導入方法依賴的package包/類
protected void onSerialization(JsonObject data)
{
    data.addProperty("created", dateFormat.format(this.banStartDate));
    data.addProperty("source", this.bannedBy);
    data.addProperty("expires", this.banEndDate == null ? "forever" : dateFormat.format(this.banEndDate));
    data.addProperty("reason", this.reason);
}
 
開發者ID:SkidJava,項目名稱:BaseClient,代碼行數:8,代碼來源:BanEntry.java

示例10: onSerialization

import com.google.gson.JsonObject; //導入方法依賴的package包/類
protected void onSerialization(JsonObject data)
{
    if (this.getValue() != null)
    {
        data.addProperty("uuid", ((GameProfile)this.getValue()).getId() == null ? "" : ((GameProfile)this.getValue()).getId().toString());
        data.addProperty("name", ((GameProfile)this.getValue()).getName());
        super.onSerialization(data);
        data.addProperty("level", (Number)Integer.valueOf(this.field_152645_a));
        data.addProperty("bypassesPlayerLimit", Boolean.valueOf(this.field_183025_b));
    }
}
 
開發者ID:SkidJava,項目名稱:BaseClient,代碼行數:12,代碼來源:UserListOpsEntry.java

示例11: serialize

import com.google.gson.JsonObject; //導入方法依賴的package包/類
@Override
public JsonElement serialize(WidgetPane src, JsonSerializationContext context) {
  JsonObject object = new JsonObject();
  object.addProperty("gridSize", src.getTileSize());
  object.addProperty("hgap", src.getHgap());
  object.addProperty("vgap", src.getVgap());
  JsonObject tiles = new JsonObject();

  for (Tile<?> tile : src.getTiles()) {
    String x = GridPane.getColumnIndex(tile).toString();
    String y = GridPane.getRowIndex(tile).toString();
    String coordinate = String.join(",", x, y);

    JsonObject tileObject = new JsonObject();
    tileObject.add("size", context.serialize(tile.getSize(), TileSize.class));
    tileObject.add("content", context.serialize(tile.getContent(), tile.getContent().getClass()));

    tiles.add(coordinate, tileObject);
  }
  object.add("tiles", tiles);

  return object;
}
 
開發者ID:wpilibsuite,項目名稱:shuffleboard,代碼行數:24,代碼來源:WidgetPaneSaver.java

示例12: serialize

import com.google.gson.JsonObject; //導入方法依賴的package包/類
@Override
public JsonElement serialize(
        final RecipeVersion recipeVersion, final Type type, final JsonSerializationContext context) {

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

    final JsonObject jsonObject = new JsonObject();

    final JsonElement sourceElement = Either.join(
        recipeVersion.source,
        context::serialize,
        context::serialize);

    jsonObject.add("source", sourceElement);

    if (recipeVersion.target.isPresent()) {
        jsonObject.addProperty("target", recipeVersion.target.get());
    }

    if (recipeVersion.dependencies.map(DependencyGroup::any).orElse(false)) {
        jsonObject.add("dependencies", context.serialize(recipeVersion.dependencies.get()));
    }

    if (recipeVersion.buckResource.isPresent()) {
        jsonObject.add("buck", context.serialize(recipeVersion.buckResource.get(), RemoteFile.class));
    }

    return jsonObject;
}
 
開發者ID:LoopPerfect,項目名稱:buckaroo,代碼行數:32,代碼來源:RecipeVersionSerializer.java

示例13: sendMessage

import com.google.gson.JsonObject; //導入方法依賴的package包/類
/**
 * @param content Content of the message to be sent
 * @return The newly sent message.
 */
public Message sendMessage(String content)
{
	JsonObject json = new JsonObject();
	json.addProperty("content", content);
	return (Message) DiscordAPI.request("POST", "/channels/" + id + "/messages", json.toString(), new Message());
}
 
開發者ID:timmyrs,項目名稱:SuprDiscordBot,代碼行數:11,代碼來源:Channel.java

示例14: shortJson

import com.google.gson.JsonObject; //導入方法依賴的package包/類
/**
 * @see GenericDefinition#shortJson()
 */
@Override
public JsonElement shortJson() {
    JsonObject json = new JsonObject();
    json.addProperty("band", band.getName());
    json.addProperty("region", region.getId());
    return json;
}
 
開發者ID:spectrumauctions,項目名稱:sats-core,代碼行數:11,代碼來源:MRVMGenericDefinition.java

示例15: updateFromSync

import com.google.gson.JsonObject; //導入方法依賴的package包/類
@Test
public void updateFromSync() {
	JsonObject data = new JsonObject();

	data.addProperty("type", "m.presence");

	JsonObject content = new JsonObject();
	content.addProperty("presence", "offline");
	data.add("content", content);

	user.update(data);

	Assert.assertEquals("User object did not parse presence sync data", user.getPresence(), User.Presence.OFFLINE);
}
 
開發者ID:Gurgy,項目名稱:Cypher,代碼行數:15,代碼來源:UserTest.java


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