@Override public String[] getCallbackIP() throws WxErrorException { String url = "https://api.weixin.qq.com/cgi-bin/getcallbackip"; String responseContent = get(url, null); JsonElement tmpJsonElement = Streams.parse(new JsonReader(new StringReader(responseContent))); JsonArray ipList = tmpJsonElement.getAsJsonObject().get("ip_list").getAsJsonArray(); String[] ipArray = new String[ipList.size()]; for (int i = 0; i < ipList.size(); i++) { ipArray[i] = ipList.get(i).getAsString(); } return ipArray; }
public static JsonArray removeElementFromJsonArray(JsonArray inputJsonArray, String key) { JsonArray outputJsonArray = new JsonArray(); for (int i = 0; i < inputJsonArray.size(); i += 1) { JsonObject jsonObject = inputJsonArray.get(i).getAsJsonObject(); outputJsonArray.add(removeElementFromJsonObject(jsonObject, key)); } return outputJsonArray; }
@Override public BlockVector3 deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { JsonArray jsonArray = json.getAsJsonArray(); if (jsonArray.size() != 3) { throw new JsonParseException("Expected array of 3 length for BlockVector3"); } double x = jsonArray.get(0).getAsInt(); double y = jsonArray.get(1).getAsInt(); double z = jsonArray.get(2).getAsInt(); return BlockVector3.at(x, y, z); } }
docRoot = new JsonParser().parse(new JsonReader(new InputStreamReader(stream))).getAsJsonObject(); JsonObject asset = docRoot.getAsJsonObject().get("asset").getAsJsonObject(); String generator = getAsString(asset, "generator"); String version = getAsString(asset, "version"); for (int i = 0; i < animations.size(); i++) { readAnimation(i);
public static void format(String json) { JsonObject jsonElement = new Gson().fromJson(json, JsonObject.class); JsonArray webServices = (JsonArray) jsonElement.get("webServices"); String webServicePath = webService.get("path").getAsString(); writeSourceFile(helper.packageInfoFile(webServicePath), applyTemplate("package-info.vm", webServiceContext)); for (JsonElement actionElement : (JsonArray) webService.get("actions")) { JsonObject action = (JsonObject) actionElement; JsonArray params = (JsonArray) action.get("params"); if (params == null || params.size() < 1) { continue; writeSourceFile(helper.requestFile(webServicePath, action.get("key").getAsString()), requestCode);
JsonArray array = element.getAsJsonArray(); List<Object> result = new ArrayList<>(array.size()); for (JsonElement item : array) { result.add(gson.fromJson(item, itemType)); Class<?> valueType = fieldBinding.singleAdapter().javaType; JsonObject object = element.getAsJsonObject(); Map<Object, Object> result = new LinkedHashMap<>(object.size()); for (Map.Entry<String, JsonElement> entry : object.entrySet()) {
if (rollups != null) for (int j = 0; j < rollups.size(); j++) JsonObject rollupObject = rollups.get(j).getAsJsonObject(); Rollup rollup = m_gson.fromJson(rollupObject, Rollup.class);
public static boolean isNotNullOrEmpty(ValidationErrors validationErrors, Object name, JsonElement value) { if (value == null) { validationErrors.addErrorMessage(name + " may not be null."); return false; } if (value.isJsonNull()) { validationErrors.addErrorMessage(name + " may not be empty."); return false; } if (value.isJsonArray() && value.getAsJsonArray().size() < 1) { validationErrors.addErrorMessage(name + " may not be an empty array."); return false; } if (!value.isJsonObject() && value.getAsString().isEmpty()) { validationErrors.addErrorMessage(name + " may not be empty."); return false; } return true; }
private class VkAudioAlbumsResponseDeserializer implements JsonDeserializer<VkAudioAlbumsResponse> { @Override public VkAudioAlbumsResponse deserialize(JsonElement json, Type type, JsonDeserializationContext context) throws JsonParseException { JsonArray jArray = (JsonArray) json; int firstInteger = jArray.get(0); //ignore the 1st int VkAudioAlbumsResponse vkAudioAlbumsResponse = new VkAudioAlbumsResponse(); for (int i=1; i<jArray.size(); i++) { JsonObject jObject = (JsonObject) jArray.get(i); //assuming you have the suitable constructor... VkAudioAlbum album = new VkAudioAlbum(jObject.get("owner_id").getAsInt(), jObject.get("album_id").getAsInt(), jObject.get("title").getAsString()); vkAudioAlbumsResponse.getResponse().add(album); } return vkAudioAlbumsResponse; } }
private void processCollision(JsonDeserializationContext context, BlockShapeData shape, JsonObject collisionInfo) { if (collisionInfo.has(PITCH_SYMMETRIC) && collisionInfo.get(PITCH_SYMMETRIC).isJsonPrimitive() && collisionInfo.get(PITCH_SYMMETRIC).getAsJsonPrimitive().isBoolean()) { shape.setPitchSymmetric(collisionInfo.get(PITCH_SYMMETRIC).getAsBoolean()); if (collisionInfo.has(YAW_SYMMETRIC) && collisionInfo.get(YAW_SYMMETRIC).isJsonPrimitive() shape.setCollisionShape(convexHull); } else if (collisionInfo.has(COLLIDERS) && collisionInfo.get(COLLIDERS).isJsonArray() && collisionInfo.get(COLLIDERS).getAsJsonArray().size() > 0) { JsonArray colliderArray = collisionInfo.get(COLLIDERS).getAsJsonArray(); processColliders(context, colliderArray, shape); } else {
@Override public String[] getCallbackIp() throws WxErrorException { String url = "https://qyapi.weixin.qq.com/cgi-bin/getcallbackip"; String responseContent = get(url, null); JsonElement tmpJsonElement = Streams.parse(new JsonReader(new StringReader(responseContent))); JsonArray jsonArray = tmpJsonElement.getAsJsonObject().get("ip_list").getAsJsonArray(); String[] ips = new String[jsonArray.size()]; for(int i = 0; i < jsonArray.size(); i++) { ips[i] = jsonArray.get(i).getAsString(); } return ips; }
private Map<String, PortBinding> mapPortBindings(JsonArray ports) { int length = ports.size(); Map<String, PortBinding> portBindings = new HashMap<>(length); for (int i = 0; i < length; i++) { JsonObject object = ports.get(i).getAsJsonObject(); portBindings.put(createPortKey(object), createPortBinding(object)); } return portBindings; } }
public List<ConsulHealthEntry> parse(String data) throws IOException { List<ConsulHealthEntry> retval = new ArrayList<>(); if (data != null) { JsonParser parser = new JsonParser(); JsonElement parsed = parser.parse(data); if (parsed instanceof JsonArray) { JsonArray array = (JsonArray) parsed; if (array.size() > 0) { for (JsonElement element : array) { JsonObject obj = (JsonObject) element; JsonElement checksArrayObj = obj.get("Checks"); ConsulHealthEntry.Status status = parseHealthStatus(checksArrayObj); obj = (JsonObject) obj.get("Service"); ConsulHealthEntry entry = new ConsulHealthEntry(obj.get("ID").getAsString(), status, obj.get("Address").getAsString(), obj.get("Port").getAsInt()); retval.add(entry); } } } } return retval; }
@Override public JsonElement apply(JsonElement original) { JsonElement result = duplicate(original); JsonElement item = path.head().navigate(result); JsonElement data = mySourcePath.head().navigate(original); if (item.isJsonObject()) { item.getAsJsonObject().add(path.tail(), data); } else if (item.isJsonArray()) { JsonArray array = item.getAsJsonArray(); int index = (path.tail().equals("-")) ? array.size() : Integer.valueOf(path.tail()); List<JsonElement> temp = new ArrayList<JsonElement>(); Iterator<JsonElement> iter = array.iterator(); while (iter.hasNext()) { JsonElement stuff = iter.next(); iter.remove(); temp.add(stuff); } temp.add(index, data); for (JsonElement stuff : temp) { array.add(stuff); } } return result; }
return; for (int i = 0; i < cameras.size(); i++) { JsonObject camObj = cameras.get(i).getAsJsonObject(); String type = getAsString(camObj, "type"); assertNotNull(type, "No type defined ofr camera"); addToCache("cameras", i, cam, cameras.size());
public void convert(JsonElement value, ColumnVector vect, int row) { if (value == null || value.isJsonNull()) { vect.noNulls = false; vect.isNull[row] = true; } else { ListColumnVector vector = (ListColumnVector) vect; JsonArray obj = value.getAsJsonArray(); vector.lengths[row] = obj.size(); vector.offsets[row] = vector.childCount; vector.childCount += vector.lengths[row]; vector.child.ensureSize(vector.childCount, true); for (int c = 0; c < obj.size(); ++c) { childrenConverter.convert(obj.get(c), vector.child, (int) vector.offsets[row] + c); } } } }
@VisibleForTesting JsonObject createOutput(JsonArray outputSchema, String[] inputRecord) { Preconditions.checkArgument(outputSchema.size() == inputRecord.length, "# of columns mismatch. Input " + inputRecord.length + " , output: " + outputSchema.size()); JsonObject outputRecord = new JsonObject(); for (int i = 0; i < outputSchema.size(); i++) { JsonObject field = outputSchema.get(i).getAsJsonObject(); String key = field.get(COLUMN_NAME_KEY).getAsString(); if (StringUtils.isEmpty(inputRecord[i]) || JSON_NULL_VAL.equalsIgnoreCase(inputRecord[i])) { outputRecord.add(key, JsonNull.INSTANCE); } else { outputRecord.add(key, convertValue(inputRecord[i], field.getAsJsonObject(DATA_TYPE_KEY))); } } return outputRecord; }
public JsonSchema getFieldSchemaAt(int i) { if (i >= this.jsonArray.size()) { return new JsonSchema(this.json); } return new JsonSchema(this.jsonArray.get(i).getAsJsonObject()); }
if (jsonElement.isJsonObject()) size = jsonElement.getAsJsonObject().entrySet().size(); size = jsonElement.getAsJsonArray().size();
@Override public Quat4f deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { if (json.isJsonArray()) { JsonArray array = json.getAsJsonArray(); if (array.size() == 4) { return new Quat4f(array.get(0).getAsFloat(), array.get(1).getAsFloat(), array.get(2).getAsFloat(), array.get(3).getAsFloat()); } } return null; } }