当前位置: 首页>>代码示例>>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;未经允许,请勿转载。