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


Java JsonElement.getAsString方法代碼示例

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


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

示例1: extensionKeyFromPackageName

import com.google.gson.JsonElement; //導入方法依賴的package包/類
@Nullable
public static String extensionKeyFromPackageName(JsonElement jsonElement) {
    JsonElement nameElement = jsonElement.getAsJsonObject().get("name");
    if (nameElement != null) {
        String name = nameElement.getAsString();
        if (name != null) {
            if (name.contains("/")) {
                String packageName = name.split("/")[1];
                if (packageName.startsWith("cms-")) {
                    packageName = packageName.replace("cms-", "");
                }

                return packageName.replaceAll("-", "_");
            }
        }
    }

    return null;
}
 
開發者ID:cedricziel,項目名稱:idea-php-typo3-plugin,代碼行數:20,代碼來源:ComposerUtil.java

示例2: jsonGetIgnoreCase

import com.google.gson.JsonElement; //導入方法依賴的package包/類
/**
 * Given the key, return the json value as String, ignoring case considerations.
 * @param data the JsonObject
 * @param fieldName the key
 * @return the value as String
 * @throws BiremeException when the JsonObject doesn't have the key
 */
public static String jsonGetIgnoreCase(JsonObject data, String fieldName) throws BiremeException {
  JsonElement element = data.get(fieldName);

  if (element == null) {
    for (Entry<String, JsonElement> iter : data.entrySet()) {
      String key = iter.getKey();

      if (key.equalsIgnoreCase(fieldName)) {
        element = iter.getValue();
        break;
      }
    }
  }

  if (element == null) {
    throw new BiremeException(
        "Not found. Record does not have a field named \"" + fieldName + "\".\n");
  }

  if (element.isJsonNull()) {
    return null;
  } else {
    return element.getAsString();
  }
}
 
開發者ID:HashDataInc,項目名稱:bireme,代碼行數:33,代碼來源:BiremeUtility.java

示例3: parseEnum

import com.google.gson.JsonElement; //導入方法依賴的package包/類
private EnumValueDescriptor parseEnum(EnumDescriptor enumDescriptor, JsonElement json)
    throws InvalidProtocolBufferException {
  String value = json.getAsString();
  EnumValueDescriptor result = enumDescriptor.findValueByName(value);
  if (result == null) {
    // Try to interpret the value as a number.
    try {
      int numericValue = parseInt32(json);
      if (enumDescriptor.getFile().getSyntax() == FileDescriptor.Syntax.PROTO3) {
        result = enumDescriptor.findValueByNumberCreatingIfUnknown(numericValue);
      } else {
        result = enumDescriptor.findValueByNumber(numericValue);
      }
    } catch (InvalidProtocolBufferException e) {
      // Fall through. This exception is about invalid int32 value we get from parseInt32() but
      // that's not the exception we want the user to see. Since result == null, we will throw
      // an exception later.
    }

    if (result == null) {
      throw new InvalidProtocolBufferException(
          "Invalid enum value: " + value + " for enum type: " + enumDescriptor.getFullName());
    }
  }
  return result;
}
 
開發者ID:SeldonIO,項目名稱:seldon-core,代碼行數:27,代碼來源:JsonFormat.java

示例4: getString

import com.google.gson.JsonElement; //導入方法依賴的package包/類
/**
 * Gets the string value of the given JsonElement.  Expects the second parameter to be the name of the element's
 * field if an error message needs to be thrown.
 */
public static String getString(JsonElement p_151206_0_, String p_151206_1_)
{
    if (p_151206_0_.isJsonPrimitive())
    {
        return p_151206_0_.getAsString();
    }
    else
    {
        throw new JsonSyntaxException("Expected " + p_151206_1_ + " to be a string, was " + toString(p_151206_0_));
    }
}
 
開發者ID:Notoh,項目名稱:DecompiledMinecraft,代碼行數:16,代碼來源:JsonUtils.java

示例5: getStringElement

import com.google.gson.JsonElement; //導入方法依賴的package包/類
protected String getStringElement(JsonObject config, String key, String subKey) {
    try {
        JsonElement value = getElement(config, key, subKey);
        if (value != null) {
            return value.getAsString();
        }
    } catch (Exception e) {
        Config.LOGGER.warn("parse jason failed because: " + e.getMessage());
    }
    return null;
}
 
開發者ID:baidu,項目名稱:openrasp,代碼行數:12,代碼來源:ConfigurableChecker.java

示例6: deserialize

import com.google.gson.JsonElement; //導入方法依賴的package包/類
@Override
public Spanned deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context)
        throws JsonParseException {
    String string = json.getAsString();
    if (string != null) {
        return HtmlUtils.fromHtml(string);
    } else {
        return new SpannedString("");
    }
}
 
開發者ID:Vavassor,項目名稱:Tusky,代碼行數:11,代碼來源:SpannedTypeAdapter.java

示例7: getDeviceName

import com.google.gson.JsonElement; //導入方法依賴的package包/類
private String getDeviceName(JsonObject jsonObject) {
  JsonElement element = jsonObject.get(IDENTIFIER_KEY);
  if (element != null) {
    return element.getAsString();
  } else {
    return null;
  }
}
 
開發者ID:edgexfoundry,項目名稱:device-mqtt,代碼行數:9,代碼來源:MqttDriver.java

示例8: getEventName

import com.google.gson.JsonElement; //導入方法依賴的package包/類
public static String getEventName(JsonObject event) {
    String eventName = null;
    if (event.has(META)) {
        eventName = event.getAsJsonObject(META).get(NAME).getAsString();
    } else {
        JsonElement eventType = event.get(EVENT_TYPE);
        if (eventType != null) {
            eventName = eventType.getAsString();
        }
    }
    return eventName;
}
 
開發者ID:Sixt,項目名稱:ja-micro,代碼行數:13,代碼來源:EventUtils.java

示例9: getString

import com.google.gson.JsonElement; //導入方法依賴的package包/類
/**
 * Gets the string value of the given JsonElement.  Expects the second parameter to be the name of the element's
 * field if an error message needs to be thrown.
 */
public static String getString(JsonElement json, String memberName)
{
    if (json.isJsonPrimitive())
    {
        return json.getAsString();
    }
    else
    {
        throw new JsonSyntaxException("Expected " + memberName + " to be a string, was " + toString(json));
    }
}
 
開發者ID:sudofox,項目名稱:Backmemed,代碼行數:16,代碼來源:JsonUtils.java

示例10: deserialize

import com.google.gson.JsonElement; //導入方法依賴的package包/類
@Override
public Date deserialize(JsonElement element, Type arg1, JsonDeserializationContext arg2) throws JsonParseException {
    String date = element.getAsString();
    SimpleDateFormat formatter = new SimpleDateFormat(RemoteConstants.DATE_TIME_FORMAT, Locale.getDefault());
    formatter.setTimeZone(TimeZone.getTimeZone("UTC"));
    try {
        return formatter.parse(date);
    } catch (ParseException e) {
        e.printStackTrace();
        return null;
    }
}
 
開發者ID:duyp,項目名稱:mvvm-template,代碼行數:13,代碼來源:GsonProvider.java

示例11: process

import com.google.gson.JsonElement; //導入方法依賴的package包/類
@Override
public ModelFluid process(ImmutableMap<String, String> customData)
{
    if(!customData.containsKey("fluid")) return this;

    String fluidStr = customData.get("fluid");
    JsonElement e = new JsonParser().parse(fluidStr);
    String fluid = e.getAsString();
    if(!FluidRegistry.isFluidRegistered(fluid))
    {
        FMLLog.severe("fluid '%s' not found", fluid);
        return WATER;
    }
    return new ModelFluid(FluidRegistry.getFluid(fluid));
}
 
開發者ID:F1r3w477,項目名稱:CustomWorldGen,代碼行數:16,代碼來源:ModelFluid.java

示例12: getValue

import com.google.gson.JsonElement; //導入方法依賴的package包/類
private static <T> T getValue(JsonElement element, T compared) throws IllegalStateException, ClassCastException, IllegalArgumentException {
    if (compared instanceof Double) {
        return (T)(new Double(element.getAsDouble()));
    }
    else if (compared instanceof Integer) {
        return (T)(new Integer(element.getAsInt()));
    }
    else if (compared instanceof JsonObject) {
        return (T)element.getAsJsonObject();
    }
    else if (compared instanceof JsonArray) {
        return (T)element.getAsJsonArray();
    }
    else if (compared instanceof String) {
        return (T)element.getAsString();
    }
    else if (compared instanceof Boolean) {
        return (T)(new Boolean(element.getAsBoolean()));
    }

    throw new IllegalArgumentException();
}
 
開發者ID:stuebz88,項目名稱:modName,代碼行數:23,代碼來源:JsonUtil.java

示例13: deserialize

import com.google.gson.JsonElement; //導入方法依賴的package包/類
@Override
public RecipeIdentifier deserialize(final JsonElement jsonElement, final Type type, final JsonDeserializationContext context) throws JsonParseException {

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

    final String string = jsonElement.getAsString();

    return RecipeIdentifier.parse(string)
            .orElseThrow(() -> new JsonParseException("\"" + string + "\" is not a valid identifier"));
}
 
開發者ID:LoopPerfect,項目名稱:buckaroo,代碼行數:13,代碼來源:RecipeIdentifierDeserializer.java

示例14: getString

import com.google.gson.JsonElement; //導入方法依賴的package包/類
public static String getString(JsonObject p_getString_0_, String p_getString_1_, String p_getString_2_)
{
    JsonElement jsonelement = p_getString_0_.get(p_getString_1_);
    return jsonelement == null ? p_getString_2_ : jsonelement.getAsString();
}
 
開發者ID:SkidJava,項目名稱:BaseClient,代碼行數:6,代碼來源:Json.java

示例15: TextValue

import com.google.gson.JsonElement; //導入方法依賴的package包/類
protected TextValue(final JsonElement v, final boolean deprecated, final String encryptionProfile)
{
    super(deprecated, encryptionProfile);
    value = v.getAsString();
}
 
開發者ID:ConfigHubPub,項目名稱:JavaAPI,代碼行數:6,代碼來源:Properties.java


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