本文整理了Java中com.google.gson.JsonElement.getAsInt()
方法的一些代码示例,展示了JsonElement.getAsInt()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。JsonElement.getAsInt()
方法的具体详情如下:
包路径:com.google.gson.JsonElement
类名称:JsonElement
方法名:getAsInt
[英]convenience method to get this element as a primitive integer value.
[中]将此元素作为基元整数值获取的方便方法。
代码示例来源:origin: SonarSource/sonarqube
private static Predicate<JsonObject> isConditionOnValidPeriod() {
return jsonCondition -> {
JsonElement periodIndex = jsonCondition.get("period");
if (periodIndex == null) {
return true;
}
int period = periodIndex.getAsInt();
// Ignore period that was set on non leak period (for retro compatibility with project that hasn't been analyzed since a while)
return period == 1;
};
}
}
代码示例来源:origin: fabric8io/docker-maven-plugin
private String createPortKey(JsonObject object) {
return String.format("%s/%s", object.get(PRIVATE_PORT).getAsInt(), object.get(TYPE).getAsString());
}
代码示例来源:origin: searchbox-io/Jest
public int getBulkRetryCount() {
return (jsonObject != null && jsonObject.has("retries") && jsonObject.getAsJsonObject("retries").has("bulk")) ? jsonObject.getAsJsonObject("retries").get("bulk").getAsInt() : 0;
}
代码示例来源:origin: konsoletyper/teavm
private void readWeekData(InputStream input) {
JsonObject root = (JsonObject) new JsonParser().parse(new InputStreamReader(input));
JsonObject weekJson = root.get("supplemental").getAsJsonObject().get("weekData").getAsJsonObject();
JsonObject minDaysJson = weekJson.get("minDays").getAsJsonObject();
for (Map.Entry<String, JsonElement> property : minDaysJson.entrySet()) {
minDaysMap.put(property.getKey(), property.getValue().getAsInt());
}
JsonObject firstDayJson = weekJson.get("firstDay").getAsJsonObject();
for (Map.Entry<String, JsonElement> property : firstDayJson.entrySet()) {
firstDayMap.put(property.getKey(), getNumericDay(property.getValue().getAsString()));
}
}
代码示例来源:origin: chanjarster/weixin-java-tools
@Override
public int invite(String userId, String inviteTips) throws WxErrorException {
String url = "https://qyapi.weixin.qq.com/cgi-bin/invite/send";
JsonObject jsonObject = new JsonObject();
jsonObject.addProperty("userid", userId);
if (StringUtils.isNotEmpty(inviteTips)) {
jsonObject.addProperty("invite_tips", inviteTips);
}
String responseContent = post(url, jsonObject.toString());
JsonElement tmpJsonElement = Streams.parse(new JsonReader(new StringReader(responseContent)));
return tmpJsonElement.getAsJsonObject().get("type").getAsInt();
}
代码示例来源:origin: MovingBlocks/Terasology
@Override
public EntityData.Entity deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
EntityData.Entity.Builder entity = EntityData.Entity.newBuilder();
JsonObject jsonObject = json.getAsJsonObject();
case "parentprefab":
if (entry.getValue().isJsonPrimitive()) {
entity.setParentPrefab(entry.getValue().getAsString());
entity.setId(entry.getValue().getAsInt());
if (entry.getValue().isJsonArray()) {
for (JsonElement element : entry.getValue().getAsJsonArray()) {
entity.addRemovedComponent(element.getAsString());
case "owner":
if (entry.getValue().isJsonPrimitive()) {
entity.setOwner(entry.getValue().getAsInt());
代码示例来源:origin: jMonkeyEngine/jmonkeyengine
private void readChild(Spatial parent, JsonElement nodeIndex) throws IOException {
Object loaded = readNode(nodeIndex.getAsInt());
if (loaded instanceof Spatial) {
Spatial spatial = ((Spatial) loaded);
((Node) parent).attachChild(spatial);
JsonObject nodeElem = nodes.get(nodeIndex.getAsInt()).getAsJsonObject();
JsonArray children = nodeElem.getAsJsonArray("children");
if (children != null) {
for (JsonElement child : children) {
readChild(spatial, child);
}
}
} else if (loaded instanceof JointWrapper) {
//parent is the Armature Node, we have to apply its transforms to the root bone's animation data
JointWrapper bw = (JointWrapper) loaded;
bw.isRoot = true;
SkinData skinData = fetchFromCache("skins", bw.skinIndex, SkinData.class);
if (skinData == null) {
return;
}
skinData.parent = parent;
}
}
代码示例来源:origin: biezhi/wechat-api
seq = jsonObject.get("Seq").getAsInt();
this.memberCount += jsonObject.get("MemberCount").getAsInt();
List<Account> memberList = WeChatUtils.fromJson(WeChatUtils.toJson(jsonObject.getAsJsonArray("MemberList")), new TypeToken<List<Account>>() {});
代码示例来源:origin: searchbox-io/Jest
return (T) id.getAsString();
Object o = id.getAsInt();
return (T) o;
代码示例来源:origin: sixt/ja-micro
/**
* provides a {@link Category} by the given {@link JsonObject}.
*
* @param object JSON element
* @return Category that is provided in JSON, if the code is not known it will fall back to {@link Category#InternalServerError}.
*/
private static Category getCategory(JsonObject object) {
Category category = Category.InternalServerError;
if (object.has(CATEGORY) && object.get(CATEGORY).isJsonPrimitive()) { // category could be an object ...
JsonPrimitive primitive = object.getAsJsonPrimitive(CATEGORY);
try {
category = Category.fromStatus(primitive.getAsInt());
} catch (NumberFormatException nfe) {
category = Category.InternalServerError;
}
} else if (object.has(CODE)) {
category = Category.fromStatus(object.get(CODE).getAsInt());
}
return category != null ? category : Category.InternalServerError;
}
代码示例来源:origin: searchbox-io/Jest
public BulkResultItem(String operation, JsonObject values) {
this.operation = operation;
this.index = values.get("_index").getAsString();
this.type = values.get("_type").getAsString();
this.id = values.has("_id") && !values.get("_id").isJsonNull() ? values.get("_id").getAsString() : null;
this.status = values.get("status").getAsInt();
this.error = values.has("error") ? values.get("error").toString() : null;
if (values.has("error") && values.get("error").isJsonObject()) {
final JsonObject errorObject = values.get("error").getAsJsonObject();
this.errorType = errorObject.has("type") ? errorObject.get("type").getAsString() : null;
this.errorReason = errorObject.has("reason") ? errorObject.get("reason").getAsString() : null;
} else {
this.errorType = null;
this.errorReason = null;
}
this.version = values.has("_version") ? values.get("_version").getAsInt() : null;
}
代码示例来源:origin: fabric8io/docker-maven-plugin
private PortBinding createPortBinding(JsonObject object) {
PortBinding binding = null;
if (object.has(PUBLIC_PORT) && object.has(IP)) {
binding = new PortBinding(object.get(PUBLIC_PORT).getAsInt(), object.get(IP).getAsString());
}
return binding;
}
代码示例来源:origin: MovingBlocks/Terasology
private void inputEventSetup(InputEvent event, JsonObject jsonObject) {
float delta = jsonObject.get("delta").getAsFloat();
boolean consumed = jsonObject.get("consumed").getAsBoolean();
EntityRef target = new RecordedEntityRef(jsonObject.get("target").getAsLong(), (LowLevelEntityManager) this.entityManager);
JsonObject aux = jsonObject.get("hitNormal").getAsJsonObject();
Vector3f hitNormal = new Vector3f(aux.get("x").getAsFloat(), aux.get("y").getAsFloat(), aux.get("z").getAsFloat());
aux = jsonObject.get("hitPosition").getAsJsonObject();
Vector3f hitPosition = new Vector3f(aux.get("x").getAsFloat(), aux.get("y").getAsFloat(), aux.get("z").getAsFloat());
aux = jsonObject.get("targetBlockPosition").getAsJsonObject();
Vector3i targetBlockPosition = new Vector3i(aux.get("x").getAsInt(), aux.get("y").getAsInt(), aux.get("z").getAsInt());
event.setTargetInfo(target, targetBlockPosition, hitPosition, hitNormal);
}
}
代码示例来源:origin: jMonkeyEngine/jmonkeyengine
public static Integer getAsInteger(JsonObject parent, String name) {
JsonElement el = parent.get(name);
return el == null ? null : el.getAsInt();
}
代码示例来源:origin: searchbox-io/Jest
public int getSearchRetryCount() {
return (jsonObject != null && jsonObject.has("retries") && jsonObject.getAsJsonObject("retries").has("search")) ? jsonObject.getAsJsonObject("retries").get("search").getAsInt() : 0;
}
代码示例来源:origin: jMonkeyEngine/jmonkeyengine
private void findChildren(int nodeIndex) throws IOException {
JointWrapper jw = fetchFromCache("nodes", nodeIndex, JointWrapper.class);
JsonObject nodeData = nodes.get(nodeIndex).getAsJsonObject();
JsonArray children = nodeData.getAsJsonArray("children");
if (children != null) {
for (JsonElement child : children) {
int childIndex = child.getAsInt();
if (jw.children.contains(childIndex)) {
//bone already has the child in its children
continue;
}
JointWrapper cjw = fetchFromCache("nodes", childIndex, JointWrapper.class);
if (cjw != null) {
jw.joint.addChild(cjw.joint);
jw.children.add(childIndex);
} else {
//The child might be a Node
//Creating a dummy node to read the subgraph
Node n = new Node();
readChild(n, child);
Spatial s = n.getChild(0);
//removing the spatial from the dummy node, it will be attached to the attachment node of the bone
s.removeFromParent();
jw.attachedSpatial = s;
}
}
}
}
代码示例来源:origin: chanjarster/weixin-java-tools
public String templateSend(WxMpTemplateMessage templateMessage) throws WxErrorException {
String url = "https://api.weixin.qq.com/cgi-bin/message/template/send";
String responseContent = execute(new SimplePostRequestExecutor(), url, templateMessage.toJson());
JsonElement tmpJsonElement = Streams.parse(new JsonReader(new StringReader(responseContent)));
final JsonObject jsonObject = tmpJsonElement.getAsJsonObject();
if (jsonObject.get("errcode").getAsInt() == 0)
return jsonObject.get("msgid").getAsString();
throw new WxErrorException(WxError.fromJson(responseContent));
}
代码示例来源:origin: fabric8io/docker-maven-plugin
private void addPortMapping(String port, JsonObject hostConfig, Map<String, PortBinding> portBindings) {
String hostIp = hostConfig.get(HOST_IP).getAsString();
Integer hostPort = Integer.valueOf(hostConfig.get(HOST_PORT).getAsInt());
addPortMapping(port, new PortBinding(hostPort, hostIp), portBindings);
}
代码示例来源:origin: apache/incubator-gobblin
JsonObject jsonBody = new JsonParser().parse(entityStr).getAsJsonObject();
if (!jsonBody.get("hasErrors").getAsBoolean()) {
return;
JsonArray results = jsonBody.get("results").getAsJsonArray();
for (JsonElement jsonElem : results) {
JsonObject json = jsonElem.getAsJsonObject();
int subStatusCode = json.get("statusCode").getAsInt();
if (subStatusCode < 400) {
continue;
JsonElement resultJsonElem = json.get("result");
Preconditions.checkNotNull(resultJsonElem, "Error response should contain result property");
JsonObject resultJsonObject = resultJsonElem.getAsJsonArray().get(0).getAsJsonObject();
if (isDuplicate(resultJsonObject, subStatusCode)) {
continue;
代码示例来源:origin: jMonkeyEngine/jmonkeyengine
public static Integer getAsInteger(JsonObject parent, String name, int defaultValue) {
JsonElement el = parent.get(name);
return el == null ? defaultValue : el.getAsInt();
}
内容来源于网络,如有侵权,请联系作者删除!