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


Java JsonElement.getAsJsonArray方法代码示例

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


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

示例1: Module

import com.google.gson.JsonElement; //导入方法依赖的package包/类
public Module(JsonObject definition, boolean submodule) throws Exception {
  name = String.format("%s Module", definition.get("name").getAsString());
  this.submodule = submodule;
  remarks = new ArrayList<String>();
  if (definition.has("remarks")) {
    JsonElement jsonRemarks = definition.get("remarks");
    for (JsonElement value : jsonRemarks.getAsJsonArray()) {
      remarks.add(value.getAsString());
    }
  }

  JsonObject jsonStates = definition.get("states").getAsJsonObject();
  states = new ConcurrentHashMap<String, State>();
  for (Entry<String, JsonElement> entry : jsonStates.entrySet()) {
    State state = State.build(this, entry.getKey(), entry.getValue().getAsJsonObject());
    states.put(entry.getKey(), state);
  }
}
 
开发者ID:synthetichealth,项目名称:synthea_java,代码行数:19,代码来源:Module.java

示例2: deserialize

import com.google.gson.JsonElement; //导入方法依赖的package包/类
@Override
public ControllableComponent deserialize(JsonElement json, Type typeOfT,
                                         JsonDeserializationContext context) throws JsonParseException {
    JsonArray arr = json.getAsJsonArray();
    
    ControllableComponent control = new ControllableComponent();
    
    Level level = Level.deserializing();
    
    arr.forEach((element) -> {
        String str = element.getAsString();
        if (level.getCommands().containsKey(str)) {
            control.commands.add(level.getCommands().get(str));
        } else {
            throw new JsonParseException("Could not find command " + str);
        }
    });
    
    return control;
}
 
开发者ID:SergeySave,项目名称:SpaceGame,代码行数:21,代码来源:ControllableComponent.java

示例3: getAsCollection

import com.google.gson.JsonElement; //导入方法依赖的package包/类
@Override
public <T, C extends Collection<T>> void getAsCollection(String key, Class<T> type, C collection)
{
    JsonElement element = this.getElement(this.element, key);
    if (element == null)
    {
        throw new DeserializationException(type, this, "Can't find valid value for key: " + key);
    }
    if (element.isJsonArray())
    {
        JsonArray jsonArray = element.getAsJsonArray();
        for (JsonElement jsonElement : jsonArray)
        {
            collection.add(this.deserializeSpecial(type, jsonElement, null));
        }
    }
    else if (element.isJsonObject())
    {
        JsonObject jsonObject = element.getAsJsonObject();
        for (Entry<String, JsonElement> entry : jsonObject.entrySet())
        {
            collection.add(this.deserializeSpecial(type, entry.getValue(), null));
        }
    }
    else
    {
        throw new DeserializationException(type, this, "Can't find valid value for key: " + key);
    }
}
 
开发者ID:GotoFinal,项目名称:diorite-configs-java8,代码行数:30,代码来源:JsonDeserializationData.java

示例4: deserialize

import com.google.gson.JsonElement; //导入方法依赖的package包/类
public VariantList deserialize(JsonElement p_deserialize_1_, Type p_deserialize_2_, JsonDeserializationContext p_deserialize_3_) throws JsonParseException
{
    List<Variant> list = Lists.<Variant>newArrayList();

    if (p_deserialize_1_.isJsonArray())
    {
        JsonArray jsonarray = p_deserialize_1_.getAsJsonArray();

        if (jsonarray.size() == 0)
        {
            throw new JsonParseException("Empty variant array");
        }

        for (JsonElement jsonelement : jsonarray)
        {
            list.add((Variant)p_deserialize_3_.deserialize(jsonelement, Variant.class));
        }
    }
    else
    {
        list.add((Variant)p_deserialize_3_.deserialize(p_deserialize_1_, Variant.class));
    }

    return new VariantList(list);
}
 
开发者ID:sudofox,项目名称:Backmemed,代码行数:26,代码来源:VariantList.java

示例5: parseVariants

import com.google.gson.JsonElement; //导入方法依赖的package包/类
protected ModelBlockDefinition.Variants parseVariants(JsonDeserializationContext p_178335_1_, Entry<String, JsonElement> p_178335_2_)
{
    String s = (String)p_178335_2_.getKey();
    List<ModelBlockDefinition.Variant> list = Lists.<ModelBlockDefinition.Variant>newArrayList();
    JsonElement jsonelement = (JsonElement)p_178335_2_.getValue();

    if (jsonelement.isJsonArray())
    {
        for (JsonElement jsonelement1 : jsonelement.getAsJsonArray())
        {
            list.add((ModelBlockDefinition.Variant)p_178335_1_.deserialize(jsonelement1, ModelBlockDefinition.Variant.class));
        }
    }
    else
    {
        list.add((ModelBlockDefinition.Variant)p_178335_1_.deserialize(jsonelement, ModelBlockDefinition.Variant.class));
    }

    return new ModelBlockDefinition.Variants(s, list);
}
 
开发者ID:SkidJava,项目名称:BaseClient,代码行数:21,代码来源:ModelBlockDefinition.java

示例6: toStringList

import com.google.gson.JsonElement; //导入方法依赖的package包/类
public static List<String> toStringList(JsonElement element) {
    JsonArray array = element.getAsJsonArray();
    List<String> list = new ArrayList<>(array.size());
    for (int i = 0; i < array.size(); i++) {
        list.add(array.get(i).getAsString());
    }
    return list;
}
 
开发者ID:feifadaima,项目名称:https-github.com-hyb1996-NoRootScriptDroid,代码行数:9,代码来源:GsonUtils.java

示例7: fromJson

import com.google.gson.JsonElement; //导入方法依赖的package包/类
public void fromJson(JsonElement json)
{
    if (json.isJsonArray())
    {
        for (JsonElement jsonelement : json.getAsJsonArray())
        {
            this.add(jsonelement.getAsString());
        }
    }
}
 
开发者ID:SkidJava,项目名称:BaseClient,代码行数:11,代码来源:JsonSerializableSet.java

示例8: fetch

import com.google.gson.JsonElement; //导入方法依赖的package包/类
public JsonArray fetch(EnumType entityType) throws IOException {
JsonElement element = getFetcher().fetch(entityType, null);
if (element == null) {
  return null;
}
if (element.isJsonArray()) {
    return element.getAsJsonArray();
} else {
  throw new JsonParseException("Invalid response from DataSourceInput. Expected "
      + "a JsonArray, but fetched "+element.getClass().getName()
      +". Entity fetcher is "+getFetcher());
}  }
 
开发者ID:dreaminglion,项目名称:iosched-reader,代码行数:13,代码来源:DataSourceInput.java

示例9: parseFloatArray

import com.google.gson.JsonElement; //导入方法依赖的package包/类
public static float[] parseFloatArray(JsonElement p_parseFloatArray_0_, int p_parseFloatArray_1_, float[] p_parseFloatArray_2_)
{
    if (p_parseFloatArray_0_ == null)
    {
        return p_parseFloatArray_2_;
    }
    else
    {
        JsonArray jsonarray = p_parseFloatArray_0_.getAsJsonArray();

        if (jsonarray.size() != p_parseFloatArray_1_)
        {
            throw new JsonParseException("Wrong array length: " + jsonarray.size() + ", should be: " + p_parseFloatArray_1_ + ", array: " + jsonarray);
        }
        else
        {
            float[] afloat = new float[jsonarray.size()];

            for (int i = 0; i < afloat.length; ++i)
            {
                afloat[i] = jsonarray.get(i).getAsFloat();
            }

            return afloat;
        }
    }
}
 
开发者ID:SkidJava,项目名称:BaseClient,代码行数:28,代码来源:Json.java

示例10: getJsonArray

import com.google.gson.JsonElement; //导入方法依赖的package包/类
/**
 * Gets the given JsonElement as a JsonArray.  Expects the second parameter to be the name of the element's field if
 * an error message needs to be thrown.
 */
public static JsonArray getJsonArray(JsonElement p_151207_0_, String p_151207_1_)
{
    if (p_151207_0_.isJsonArray())
    {
        return p_151207_0_.getAsJsonArray();
    }
    else
    {
        throw new JsonSyntaxException("Expected " + p_151207_1_ + " to be a JsonArray, was " + toString(p_151207_0_));
    }
}
 
开发者ID:SkidJava,项目名称:BaseClient,代码行数:16,代码来源:JsonUtils.java

示例11: ListValue

import com.google.gson.JsonElement; //导入方法依赖的package包/类
protected ListValue(final JsonElement v, final boolean deprecated, final String encryptionProfile)
{
    super(deprecated, encryptionProfile);

    Type listType = new TypeToken<List<String>>() {}.getType();
    JsonArray arr = v.getAsJsonArray();
    this.json = v.toString();
    this.value = new Gson().fromJson(arr, listType);
}
 
开发者ID:ConfigHubPub,项目名称:JavaAPI,代码行数:10,代码来源:Properties.java

示例12: getBindingsArray

import com.google.gson.JsonElement; //导入方法依赖的package包/类
private JsonArray getBindingsArray() {
	JsonElement varArray;
	if (results == null) return null;
	if((varArray=results.get("results")) == null) return null;
	if((varArray=varArray.getAsJsonObject().get("bindings"))==null) return null;
	
	return varArray.getAsJsonArray();	
}
 
开发者ID:vaimee,项目名称:sepatools,代码行数:9,代码来源:BindingsResults.java

示例13: getVariablesArray

import com.google.gson.JsonElement; //导入方法依赖的package包/类
private JsonArray getVariablesArray() {
	JsonElement varArray;
	if (results == null) return null;
	if ((varArray = results.get("head")) == null) return null;
	if ((varArray = varArray.getAsJsonObject().get("vars")) == null) return null;
	
	return varArray.getAsJsonArray();	
}
 
开发者ID:vaimee,项目名称:sepatools,代码行数:9,代码来源:BindingsResults.java

示例14: importPreferencesFromJson

import com.google.gson.JsonElement; //导入方法依赖的package包/类
@SuppressLint("ApplySharedPref")
private static void importPreferencesFromJson(Context context, Reader reader) {
    SharedPreferences.Editor prefs = PreferenceManager.getDefaultSharedPreferences(context).edit();
    SettingsHelper.getInstance(context).clear();
    JsonObject obj = SettingsHelper.getGson().fromJson(reader, JsonObject.class);
    for (Map.Entry<String, JsonElement> entry : obj.entrySet()) {
        JsonElement el = entry.getValue();
        if (el.isJsonArray()) {
            Set<String> items = new HashSet<>();
            for (JsonElement child : el.getAsJsonArray())
                items.add(child.getAsString());
            prefs.putStringSet(entry.getKey(), items);
        } else {
            JsonPrimitive primitive = el.getAsJsonPrimitive();
            if (primitive.isBoolean()) {
                prefs.putBoolean(entry.getKey(), primitive.getAsBoolean());
            } else if (primitive.isNumber()) {
                Number number = primitive.getAsNumber();
                if (number instanceof Float || number instanceof Double)
                    prefs.putFloat(entry.getKey(), number.floatValue());
                else if (number instanceof Long)
                    prefs.putLong(entry.getKey(), number.longValue());
                else
                    prefs.putInt(entry.getKey(), number.intValue());
            } else if (primitive.isString()) {
                prefs.putString(entry.getKey(), primitive.getAsString());
            }
        }
    }
    prefs.commit(); // This will be called asynchronously
}
 
开发者ID:MCMrARM,项目名称:revolution-irc,代码行数:32,代码来源:BackupManager.java

示例15: dataFromJson

import com.google.gson.JsonElement; //导入方法依赖的package包/类
@Override
protected void dataFromJson(final JsonElement data)
{
    if (!data.isJsonArray())
        throw new IllegalArgumentException("json is not an array");
    final JsonArray array = data.getAsJsonArray();

    array.forEach((trans) ->
    {
        if (trans.isJsonObject())
        {
            final JsonObject transObj = trans.getAsJsonObject();
            final String key = transObj.get("key").getAsString();
            this.addKey(key);
            final JsonArray translations = transObj.get("translations").getAsJsonArray();

            translations.forEach((elem) ->
            {
                if (elem.isJsonObject())
                {
                    final JsonObject elemObj = elem.getAsJsonObject();
                    final String lang = elemObj.get("lang").getAsString();
                    this.addLanguage(lang);
                    this.setTranslation(key, lang, elemObj.get("value").getAsString());
                }
            });
        }
    });
}
 
开发者ID:Leviathan-Studio,项目名称:MineIDE,代码行数:30,代码来源:Translation.java


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