本文整理匯總了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;
}