當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。