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


Java JsonPrimitive.getAsString方法代码示例

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


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

示例1: deserialize

import com.google.gson.JsonPrimitive; //导入方法依赖的package包/类
@Override
public Order deserialize(JsonElement json, Type arg1,
        JsonDeserializationContext context) throws JsonParseException {
    JsonObject jsonObject =  json.getAsJsonObject();
    JsonPrimitive prim = (JsonPrimitive) jsonObject.get("type");
    String typestring = prim.getAsString();
    OrderType type = OrderType.valueOf(typestring);

    switch (type) {
    case MARKET:
        return context.deserialize(json, MarketOrder.class);
    case LIMIT:
        return context.deserialize(json, LimitOrder.class);
    case STOP:
        return context.deserialize(json, StopOrder.class);
    case MARKET_IF_TOUCHED:
        return context.deserialize(json, MarketIfTouchedOrder.class);
    case TAKE_PROFIT:
        return context.deserialize(json, TakeProfitOrder.class);
    case STOP_LOSS:
        return context.deserialize(json, StopLossOrder.class);
    case TRAILING_STOP_LOSS:
        return context.deserialize(json, TrailingStopLossOrder.class);
    }
    return null;
}
 
开发者ID:oanda,项目名称:v20-java,代码行数:27,代码来源:OrderAdapter.java

示例2: convert

import com.google.gson.JsonPrimitive; //导入方法依赖的package包/类
@Override
public JsonPrimitive convert(JsonPrimitive value) {
  if (value == null) {
    return new JsonPrimitive(false);
  }
  if (value.isBoolean()) {
    return value;
  }
  String str = value.getAsString();
  if (str.equalsIgnoreCase("false")) {
    return new JsonPrimitive(false);
  }
  if (str.equalsIgnoreCase("true")) {
    return new JsonPrimitive(true);
  }
  throw new ConverterException(value, this);
}
 
开发者ID:dreaminglion,项目名称:iosched-reader,代码行数:18,代码来源:BooleanConverter.java

示例3: primitive

import com.google.gson.JsonPrimitive; //导入方法依赖的package包/类
/**
 * Converts a JsonPrimitive into a primitive Boolean, Double, or String.
 * 
 * @param p
 *          : JsonPrimitive
 * @return Boolean, Double, or String
 */
public static Object primitive(JsonPrimitive p) {
  Object retVal = null;
  if (p.isBoolean()) {
    retVal = p.getAsBoolean();
  } else if (p.isNumber()) {
    double doubleVal = p.getAsDouble();

    if (doubleVal == Math.rint(doubleVal)) {
      retVal = (int) doubleVal;
    } else {
      retVal = doubleVal;
    }
  } else if (p.isString()) {
    retVal = p.getAsString();
  }
  return retVal;
}
 
开发者ID:synthetichealth,项目名称:synthea_java,代码行数:25,代码来源:Utilities.java

示例4: update

import com.google.gson.JsonPrimitive; //导入方法依赖的package包/类
private void update() {
	try {
		URLConnection conn = new URL(url).openConnection();
		conn.setConnectTimeout(10000);
		conn.setReadTimeout(10000);
		String json = "";
		try (BufferedReader reader = new BufferedReader(
				new InputStreamReader(conn.getInputStream(), StandardCharsets.UTF_8))) {
			json = reader.lines().collect(Collectors.joining("\n"));
		}
		json = json.trim().replaceAll("\\[", "").replaceAll("\\]", ""); //quick and dirty fix
		
		JsonObject jsonObject = new Gson().fromJson(json, JsonObject.class);
		JsonPrimitive priceDollars = jsonObject.getAsJsonPrimitive("price_usd");
		
		price = priceDollars.getAsString();
		int maxIndex = price.indexOf(".") + 3;
		if (price.length() >= maxIndex)
			price = price.substring(0, maxIndex);
	} catch (Exception e) {
		e.printStackTrace();
		price = "0.00";
	}
	price = "{\"price\":\"" + price + "\"}";
}
 
开发者ID:thehen101,项目名称:RainServer,代码行数:26,代码来源:CommandPrice.java

示例5: keyToString

import com.google.gson.JsonPrimitive; //导入方法依赖的package包/类
private String keyToString(JsonElement keyElement) {
    if (keyElement.isJsonPrimitive()) {
        JsonPrimitive primitive = keyElement.getAsJsonPrimitive();
        if (primitive.isNumber()) {
            return String.valueOf(primitive.getAsNumber());
        }
        if (primitive.isBoolean()) {
            return Boolean.toString(primitive.getAsBoolean());
        }
        if (primitive.isString()) {
            return primitive.getAsString();
        }
        throw new AssertionError();
    } else if (keyElement.isJsonNull()) {
        return "null";
    } else {
        throw new AssertionError();
    }
}
 
开发者ID:JackChan1999,项目名称:letv,代码行数:20,代码来源:MapTypeAdapterFactory.java

示例6: keyToString

import com.google.gson.JsonPrimitive; //导入方法依赖的package包/类
private String keyToString(JsonElement keyElement) {
  if (keyElement.isJsonPrimitive()) {
    JsonPrimitive primitive = keyElement.getAsJsonPrimitive();
    if (primitive.isNumber()) {
      return String.valueOf(primitive.getAsNumber());
    } else if (primitive.isBoolean()) {
      return Boolean.toString(primitive.getAsBoolean());
    } else if (primitive.isString()) {
      return primitive.getAsString();
    } else {
      throw new AssertionError();
    }
  } else if (keyElement.isJsonNull()) {
    return "null";
  } else {
    throw new AssertionError();
  }
}
 
开发者ID:odoo-mobile-intern,项目名称:odoo-work,代码行数:19,代码来源:MapTypeAdapterFactory.java

示例7: convert

import com.google.gson.JsonPrimitive; //导入方法依赖的package包/类
@Override
public JsonPrimitive convert(JsonPrimitive value) {
  if (value == null) {
    if (acceptsNull) {
      return null;
    } else {
      throw new ConverterException(value, this);
    }
  }
  String str = value.getAsString();
  if (str.isEmpty() || pattern.matcher(str).matches()) {
    return value;
  } else {
    throw new ConverterException(value, this);
  }
}
 
开发者ID:dreaminglion,项目名称:iosched-reader,代码行数:17,代码来源:RegexpConverter.java

示例8: convert

import com.google.gson.JsonPrimitive; //导入方法依赖的package包/类
@Override
public JsonPrimitive convert(JsonPrimitive value) {
  if (value == null) {
    return null;
  }
  String str = value.getAsString();
  if (str.isEmpty()) {
    return value;
  }
  for (Pattern p: plusRecognizedPatterns) {
    Matcher m = p.matcher(str);
    if (m.find()) {
      return new JsonPrimitive(plusFormat.format(new String[]{m.group(1)}));
    }
  }

  // If URL starts with http/https:
  if (acceptableUrlPattern.matcher(str).matches()) {
    return value;
  }

  // Otherwise, just add https://:
  str = "https://" + str;
  return new JsonPrimitive(str);
}
 
开发者ID:dreaminglion,项目名称:iosched-reader,代码行数:26,代码来源:GPlusURLConverter.java

示例9: unwarpPrimitive

import com.google.gson.JsonPrimitive; //导入方法依赖的package包/类
@Override
public Object unwarpPrimitive(JsonPrimitive primitive) {
    if (primitive.isBoolean()) {
        return primitive.getAsBoolean();
    } else if (primitive.isNumber()) {
        return primitive.getAsNumber();
    } else if (primitive.isString()) {
        return primitive.getAsString();
    } else {
        throw new IllegalArgumentException("Unknown primitive type: " + primitive);
    }
}
 
开发者ID:lucko,项目名称:helper,代码行数:13,代码来源:AbstractGsonConverter.java

示例10: deserialize

import com.google.gson.JsonPrimitive; //导入方法依赖的package包/类
@Override
public SchoolClazzDto deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
    JsonArray root = json.getAsJsonArray();
    SchoolClazzDto dto = new SchoolClazzDto();
    dto.id = optInt(root, 0);

    JsonPrimitive second = root.get(1).getAsJsonPrimitive();
    if(second.isString()){
        dto.title = second.getAsString();
    } else if(second.isNumber()){
        dto.title = String.valueOf(second.getAsNumber());
    }

    return dto;
}
 
开发者ID:PhoenixDevTeam,项目名称:Phoenix-for-VK,代码行数:16,代码来源:SchoolClazzDtoAdapter.java

示例11: replaceWithTestData

import com.google.gson.JsonPrimitive; //导入方法依赖的package包/类
private static String replaceWithTestData(final JsonElement sourceTestData, String inputString) {
if(sourceTestData != null) {
        if(inputString != null) {
            if(inputString.startsWith("$(") && inputString.endsWith(")")) {
                inputString = inputString.substring("$(".length(), inputString.length() - ")".length());

                String[] pathElements = inputString.split("\\.");
                if(pathElements != null && pathElements.length > 0) {
                    JsonElement elemPointer = sourceTestData;
                    for(String element : pathElements) {
                        if(elemPointer.isJsonObject() && elemPointer.getAsJsonObject().has(element)) {
                            elemPointer = elemPointer.getAsJsonObject().get(element);
                            continue;
                        }
                        else {
                            elemPointer = null;
                            break;
                        }
                    }
                    if(elemPointer != null && elemPointer.isJsonPrimitive()) {
                        JsonPrimitive primitive = elemPointer.getAsJsonPrimitive();
                        if(primitive.isString() || primitive.isNumber())
                            return primitive.getAsString();
                        else if(primitive.isBoolean())
                            return primitive.getAsBoolean()?"true":"false";
                    }
                }
            }
        }
    }
    return inputString;
}
 
开发者ID:andrewjc,项目名称:kheera-testrunner-android,代码行数:33,代码来源:TableConverter.java

示例12: convert

import com.google.gson.JsonPrimitive; //导入方法依赖的package包/类
@Override
public JsonPrimitive convert(JsonPrimitive sessionId) {
  if (sessionId == null) {
    return null;
  }
  // TODO: Replace with URL shortener and move this processing to a taskqueue.
  return new JsonPrimitive(SESSION_BASE_URL + sessionId.getAsString());
}
 
开发者ID:dreaminglion,项目名称:iosched-reader,代码行数:9,代码来源:SessionURLConverter.java

示例13: read

import com.google.gson.JsonPrimitive; //导入方法依赖的package包/类
public Object read(JsonElement in) {
  
  if (in.isJsonArray()) {
    List<Object> list = new ArrayList<Object>();
    JsonArray arr = in.getAsJsonArray();
    for (JsonElement anArr : arr) {
      list.add(read(anArr));
    }
    return list;
  } else if (in.isJsonObject()) {
    Map<String, Object> map = new LinkedTreeMap<String, Object>();
    JsonObject obj = in.getAsJsonObject();
    Set<Map.Entry<String, JsonElement>> entitySet = obj.entrySet();
    for (Map.Entry<String, JsonElement> entry: entitySet) {
      map.put(entry.getKey(), read(entry.getValue()));
    }
    return map;
  } else if (in.isJsonPrimitive()) {
    JsonPrimitive prim = in.getAsJsonPrimitive();
    if (prim.isBoolean()) {
      return prim.getAsBoolean();
    } else if (prim.isString()) {
      return prim.getAsString();
    } else if (prim.isNumber()) {
      Number num = prim.getAsNumber();
      // here you can handle double int/long values
      // and return any type you want
      // this solution will transform 3.0 float to long values
      if (Math.abs(Math.ceil(num.doubleValue())-num.longValue()) < .0000001) {
        return num.intValue();
      } else {
        return num.doubleValue();
      }
    }
  }
  return null;
}
 
开发者ID:Huawei,项目名称:Server_Management_Common_eSightApi,代码行数:38,代码来源:JsonUtil.java

示例14: decryptCardCode

import com.google.gson.JsonPrimitive; //导入方法依赖的package包/类
/**
 * 卡券Code解码
 *
 * @param encryptCode 加密Code,通过JSSDK的chooseCard接口获得
 * @return 解密后的Code
 */
@Override
public String decryptCardCode(String encryptCode) throws WxErrorException {
  String url = "https://api.weixin.qq.com/card/code/decrypt";
  JsonObject param = new JsonObject();
  param.addProperty("encrypt_code", encryptCode);
  String responseContent = this.wxMpService.post(url, param.toString());
  JsonElement tmpJsonElement = new JsonParser().parse(responseContent);
  JsonObject tmpJsonObject = tmpJsonElement.getAsJsonObject();
  JsonPrimitive jsonPrimitive = tmpJsonObject.getAsJsonPrimitive("code");
  return jsonPrimitive.getAsString();
}
 
开发者ID:11590692,项目名称:Wechat-Group,代码行数:18,代码来源:WxMpCardServiceImpl.java

示例15: setVideoForVideoSession

import com.google.gson.JsonPrimitive; //导入方法依赖的package包/类
private JsonPrimitive  setVideoForVideoSession(JsonObject origin, JsonObject dest) {
  JsonPrimitive vid = getVideoFromTopicInfo(origin,
      InputJsonKeys.VendorAPISource.Topics.INFO_VIDEO_URL, null);
  if (vid != null) {
    set(vid, dest, OutputJsonKeys.VideoLibrary.vid);
    JsonPrimitive thumbnail = new JsonPrimitive("http://img.youtube.com/vi/" + vid.getAsString() + "/hqdefault.jpg");
    set(thumbnail, dest, OutputJsonKeys.VideoLibrary.thumbnailUrl);
  }
  return vid;
}
 
开发者ID:dreaminglion,项目名称:iosched-reader,代码行数:11,代码来源:DataExtractor.java


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