本文整理汇总了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;
}
示例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();
}
}
示例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;
}
示例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_));
}
}
示例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;
}
示例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("");
}
}
示例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;
}
}
示例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;
}
示例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));
}
}
示例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;
}
}
示例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));
}
示例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();
}
示例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"));
}
示例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();
}
示例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();
}