本文整理汇总了Java中com.google.gson.JsonObject.getAsJsonArray方法的典型用法代码示例。如果您正苦于以下问题:Java JsonObject.getAsJsonArray方法的具体用法?Java JsonObject.getAsJsonArray怎么用?Java JsonObject.getAsJsonArray使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.gson.JsonObject
的用法示例。
在下文中一共展示了JsonObject.getAsJsonArray方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: parseTeamSpawns
import com.google.gson.JsonObject; //导入方法依赖的package包/类
private void parseTeamSpawns(Match match) {
JsonArray jsonArray = match.getMapContainer().getMapInfo().getJsonObject().getAsJsonArray("spawns");
for (JsonElement spawnElement : jsonArray) {
JsonObject spawnJson = spawnElement.getAsJsonObject();
List<MatchTeam> teams = new ArrayList<>();
for (JsonElement o : spawnJson.getAsJsonArray("teams")) {
String teamId = o.getAsString();
MatchTeam team = match.getModule(TeamManagerModule.class).getTeamById(teamId);
if (team != null) {
teams.add(team);
}
}
Location location;
if (spawnJson.has("coords")) {
location = Parser.convertLocation(match.getWorld(), spawnJson.get("coords"));
} else {
location = Parser.convertLocation(match.getWorld(), spawnJson);
}
SpawnPoint spawnPoint = new SpawnPoint(location);
for (MatchTeam matchTeam : teams) {
matchTeam.addSpawnPoint(spawnPoint);
}
}
}
示例2: parseAliasesEvent
import com.google.gson.JsonObject; //导入方法依赖的package包/类
private void parseAliasesEvent(JsonObject content, String stateKey, int originServerTs, String sender, String eventId, int age) {
if (content.has("aliases") &&
content.get("aliases").isJsonArray()) {
JsonArray aliases = content.getAsJsonArray("aliases");
ObservableList<String> list =
FXCollections.synchronizedObservableList(FXCollections.observableArrayList());
for (JsonElement alias : aliases) {
list.add(alias.getAsString());
}
Event event = addPropertyChangeEvent(originServerTs, sender, eventId, stateKey, age, "aliases", list);
if (isLatestStateEvent(event)) {
if (list.size() == 0){
this.aliasLists.remove(stateKey);
} else{
this.aliasLists.put(stateKey, list);
}
}
}
}
示例3: deserialize
import com.google.gson.JsonObject; //导入方法依赖的package包/类
@Override
public UserArray deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
JsonObject root = json.getAsJsonObject();
UserArray dto = new UserArray();
dto.count = optInt(root, "count");
if(root.has("items")){
JsonArray array = root.getAsJsonArray("items");
dto.ids = new int[array.size()];
for(int i = 0; i < array.size(); i++){
dto.ids[i] = array.get(i).getAsJsonObject().get("from_id").getAsInt();
}
} else {
dto.ids = new int[0];
}
return dto;
}
示例4: parseAddress
import com.google.gson.JsonObject; //导入方法依赖的package包/类
public String parseAddress(String result){
JsonParser parser = new JsonParser();
JsonObject json = (JsonObject) parser.parse(result);
JsonElement jsonCode = json.get("status");
String code = jsonCode.getAsString();
if(! (code.equals("OK"))){
return null;
}
JsonArray jsonArray = json.getAsJsonArray("results");
JsonElement elm = jsonArray.get(0);
JsonObject obj = elm.getAsJsonObject();
JsonElement ob2 = obj.get("formatted_address");
return ob2.getAsString();
}
示例5: SkriptServerResponse
import com.google.gson.JsonObject; //导入方法依赖的package包/类
public SkriptServerResponse(JsonElement element) {
JsonObject json = element.getAsJsonObject();
address = json.get("address").getAsString();
online = json.get("online").getAsBoolean();
if (online) {
latency = json.get("latency").getAsFloat();
JsonObject playersJson = json.getAsJsonObject("players");
onlinePlayers = playersJson.get("online").getAsInt();
maxPlayers = playersJson.get("max").getAsInt();
playersList = new ArrayList<>();
JsonArray playersListJson = playersJson.getAsJsonArray("list");
for (JsonElement player : playersListJson) {
playersList.add(player.getAsString());
}
JsonObject versionJson = json.getAsJsonObject("version");
version = versionJson.get("name").getAsString();
protocol = versionJson.get("protocol").getAsInt();
description = json.get("description").getAsString();
favicon = json.get("favicon").getAsString();
} else {
latency = null;
onlinePlayers = null;
maxPlayers = null;
playersList = null;
version = null;
protocol = null;
description = null;
favicon = null;
}
}
示例6: isVideoSession
import com.google.gson.JsonObject; //导入方法依赖的package包/类
private boolean isVideoSession(JsonObject sessionObj) {
JsonArray tags= sessionObj.getAsJsonArray(InputJsonKeys.VendorAPISource.Topics.categoryids.name());
for (JsonElement category: tags) {
if (Config.VIDEO_CATEGORY.equals(category.getAsString())) {
return true;
}
}
return false;
}
示例7: Message
import com.google.gson.JsonObject; //导入方法依赖的package包/类
public Message(JsonObject jsonObject) {
JsonArray contentJsonArray = jsonObject.getAsJsonArray("content");
this.font = GsonUtil.gson.fromJson(contentJsonArray.get(0).getAsJsonArray().get(1), Font.class);
final int contentJsonArraySize = contentJsonArray.size();
contentElements = new ArrayList<>(contentJsonArraySize - 1);
for (int i = 1; i < contentJsonArraySize; i++) {
contentElements.add(MessageContentElementUtil.fromJson(contentJsonArray.get(i)));
}
this.time = jsonObject.get("time").getAsLong();
this.userId = jsonObject.get("from_uin").getAsLong();
}
示例8: deserialize
import com.google.gson.JsonObject; //导入方法依赖的package包/类
@Override
public VKApiPhotoAlbum deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
JsonObject root = json.getAsJsonObject();
VKApiPhotoAlbum album = new VKApiPhotoAlbum();
album.id = optInt(root, "id");
album.thumb_id = optInt(root, "thumb_id");
album.owner_id = optInt(root, "owner_id");
album.title = optString(root, "title");
album.description = optString(root, "description");
album.created = optLong(root, "created");
album.updated = optLong(root, "updated");
album.size = optInt(root, "size");
album.can_upload = optInt(root, "can_upload") == 1;
album.thumb_src = optString(root, "thumb_src");
if(root.has("privacy_view")){
album.privacy_view = context.deserialize(root.getAsJsonArray("privacy_view"), VkApiPrivacy.class);
}
if(root.has("privacy_comment")){
album.privacy_comment = context.deserialize(root.getAsJsonArray("privacy_comment"), VkApiPrivacy.class);
}
if(root.has("sizes")){
JsonArray sizesArray = root.getAsJsonArray("sizes");
album.photo = new ArrayList<>(sizesArray.size());
for(int i = 0; i < sizesArray.size(); i++){
album.photo.add(context.deserialize(sizesArray.get(i).getAsJsonObject(), PhotoSizeDto.class));
}
} else {
album.photo = new ArrayList<>(3);
album.photo.add(PhotoSizeDto.create(PhotoSizeDto.Type.S, "http://vk.com/images/s_noalbum.png"));
album.photo.add(PhotoSizeDto.create(PhotoSizeDto.Type.M, "http://vk.com/images/m_noalbum.png"));
album.photo.add(PhotoSizeDto.create(PhotoSizeDto.Type.X, "http://vk.com/images/x_noalbum.png"));
}
album.upload_by_admins_only = optInt(root, "upload_by_admins_only") == 1;
album.comments_disabled = optInt(root, "comments_disabled") == 1;
return album;
}
示例9: filterGroups
import com.google.gson.JsonObject; //导入方法依赖的package包/类
public byte[] filterGroups(HttpServletRequest request, byte[] content) {
byte[] newContent = content;
if (ArrayUtils.isEmpty(newContent)) {
return newContent;
}
try {
String method = request.getMethod();
String uri = request.getRequestURI();
String queryString = request.getQueryString();
String path = uri + "?" + queryString;
String url = AuthUtil.QUERY_GROUP_URI;
if (AuthUtil.HTTP_GET.equalsIgnoreCase(method) && path.equalsIgnoreCase(url)) {
String umContent = MessageGZIP.uncompressToString(newContent);
User user = AuthUtil.THREAD_LOCAL_USER.get();
if (user == null) {
log.warn("AuthUtil.THREAD_LOCAL_USER.get()");
return null;
}
JsonObject jsonObject = new JsonParser().parse(umContent)
.getAsJsonObject();
// 新的jsonArrayGroups
JsonArray newJsonArrayGroups = new JsonArray();
JsonArray jsonArrayGroups = jsonObject.getAsJsonArray("groups");
log.info("jsonArrayGroups.size >>>>>{}", jsonArrayGroups.size());
if (!jsonArrayGroups.isJsonNull()) {
for (JsonElement jsonElement : jsonArrayGroups) {
JsonObject jsonObjectGroup = jsonElement
.getAsJsonObject();
String id = jsonObjectGroup.get("id").getAsString();
Permission permission = AuthUtil
.getQueryPermission(user);
log.info(" path >>>>>> {} permission >>>> {}", id,permission);
if (permission != null) {
String queryPath = permission.getOn();
// 判断分组查询权限
if ("/".equals(queryPath) || queryPath.contains(id)) {
newJsonArrayGroups.add(jsonElement);
}
}
}
}
jsonObject.remove("groups");
jsonObject.add("groups", newJsonArrayGroups);
String newContentStr = jsonObject.toString();
newContent = MessageGZIP.compressToByte(newContentStr);
log.info("newJsonArrayGroups.size >>>>>{}", newJsonArrayGroups.size());
}
} catch (Exception e) {
log.error(e.getMessage(), e);
}
return newContent;
}
示例10: cacheSkin
import com.google.gson.JsonObject; //导入方法依赖的package包/类
private void cacheSkin(SkinData skindata){
JsonObject jsonFile = getChacheFile(plugin);
JsonArray newskindata = new JsonArray();
if(jsonFile!=null){
JsonArray oldskindata = jsonFile.getAsJsonArray("skindata");
Iterator it = oldskindata.iterator();
while(it.hasNext()){
JsonElement element = (JsonElement) it.next();
if(element.getAsJsonObject().get("id").getAsInt()==this.npcid){
// element.getAsJsonObject().remove("value");
//element.getAsJsonObject().remove("signature");
//element.getAsJsonObject().addProperty("value", skindata.getValue());
//element.getAsJsonObject().addProperty("signature", skindata.getSignature());
}else {
newskindata.add(element);
}
}
}
JsonObject skin = new JsonObject();
skin.addProperty("id", this.npcid);
skin.addProperty("value", skindata.getValue());
skin.addProperty("signature", skindata.getSignature());
newskindata.add(skin);
JsonObject obj = new JsonObject();
obj.add("skindata", newskindata);
try {
plugin.getDataFolder().mkdir();
File file = new File(plugin.getDataFolder().getPath()+"/truenonpcdata.json");
file.createNewFile();
FileWriter writer = new FileWriter(file);
writer.write(obj.toString());
writer.close();
} catch (Exception e) {
e.printStackTrace();
}
}
示例11: testVersion
import com.google.gson.JsonObject; //导入方法依赖的package包/类
/**
* Test that rfiles created by a specific version of PACE still work correctly.
*
* @param versionConfig
* Configuration for the version with which the rfiles were generated.
*/
private void testVersion(File versionConfig) throws Exception {
String parentDirectory = versionConfig.getParent();
JsonParser parser = new JsonParser();
JsonObject configJson = parser.parse(new FileReader(versionConfig)).getAsJsonObject();
// Get a scanner for the data file.
List<byte[]> auths = new ArrayList<>();
for (JsonElement authElem : configJson.getAsJsonArray("authorizations")) {
auths.add(VisibilityEvaluator.escape(authElem.getAsString().getBytes(Utils.VISIBILITY_CHARSET), false));
}
Authorizations authorizations = new Authorizations(auths);
LocalFileSystem fs = FileSystem.getLocal(new Configuration());
Scanner dataScanner = RFile.newScanner().from(Paths.get(parentDirectory, configJson.getAsJsonPrimitive("data-table").getAsString()).toString())
.withFileSystem(fs).withAuthorizations(authorizations).build();
// Validate each configuration.
for (JsonElement testElem : configJson.getAsJsonArray("tests")) {
JsonObject test = testElem.getAsJsonObject();
EncryptionConfig encryptionConfig = new EncryptionConfigBuilder().readFromFile(
new FileReader(Paths.get(parentDirectory, test.getAsJsonPrimitive("config").getAsString()).toFile())).build();
EncryptionKeyContainer keyContainer = LocalEncryptionKeyContainer.read(new FileReader(Paths.get(parentDirectory,
test.getAsJsonPrimitive("keys").getAsString()).toFile()));
EntryEncryptor decryptor = new EntryEncryptor(encryptionConfig, keyContainer);
Scanner encryptedScanner = RFile.newScanner().from(Paths.get(parentDirectory, test.getAsJsonPrimitive("table").getAsString()).toString())
.withFileSystem(fs).withAuthorizations(authorizations).build();
runTest(dataScanner, encryptedScanner, decryptor);
}
}
示例12: PackageGameTemplate
import com.google.gson.JsonObject; //导入方法依赖的package包/类
public PackageGameTemplate(String id, JsonElement data)
{
this.id = id;
JsonObject object = data.getAsJsonObject();
for (JsonElement element : object.getAsJsonArray("Templates"))
{
templates.add(element.getAsString());
}
}
示例13: getCachedSkin
import com.google.gson.JsonObject; //导入方法依赖的package包/类
private SkinData getCachedSkin(){
JsonObject jsonFile = getChacheFile(plugin);
JsonArray oldskindata = jsonFile.getAsJsonArray("skindata");
Iterator it = oldskindata.iterator();
SkinData skin = null;
while(it.hasNext()){
JsonElement element = (JsonElement) it.next();
if(element.getAsJsonObject().get("id").getAsInt()==this.npcid){
String value = element.getAsJsonObject().get("value").getAsString();
String signature = element.getAsJsonObject().get("signature").getAsString();
skin = new SkinData(value, signature);
}
}
return skin;
}
示例14: doInBackground
import com.google.gson.JsonObject; //导入方法依赖的package包/类
@Override
protected JsonArray doInBackground(String... search_parameters) {
verifySettings();
JsonArray userData = null;
Gson g = new GsonBuilder().setPrettyPrinting().create();
JsonObject queryjson = new JsonObject();
JsonParser jsonParser = new JsonParser();
queryjson.addProperty("size", 1000);
queryjson.add("query",jsonParser.parse(search_parameters[1]));
// TODO Build the query
String query = g.toJson(queryjson);
Search search = new Search.Builder(query)
.addIndex(INDEX)
.addType(search_parameters[0])
.build();
Log.d("ESC.QUERY.INPUT", query);
try {
// TODO get the results of the query
SearchResult result = client.execute(search);
String s = g.toJson(result.getJsonObject());
Log.d("ESC.QUERY.RESULT", s);
JsonObject hits = result.getJsonObject().getAsJsonObject("hits");
if (result.isSucceeded()) {
userData = hits.getAsJsonArray("hits");
} else {
Log.i("ESC.QUERY.FAIL", "The search query failed to find any users that " +
"matched");
}
} catch (Exception e) {
Log.i("ESC.QUERY.EXCEPTION", "Something went wrong when we tried to communicate " +
"with the elasticsearch server!");
}
return userData;
}
示例15: afterRead
import com.google.gson.JsonObject; //导入方法依赖的package包/类
@Override
protected void afterRead(SignedTransaction source, JsonElement deserialized) {
JsonObject jsonObject = deserialized.getAsJsonObject();
JsonArray jsonArray = jsonObject.getAsJsonArray("scope");
if ( null != jsonArray ){
source.setScopeList( toAccountNameList( jsonArray ));
}
jsonArray = jsonObject.getAsJsonArray("read_scope");
if ( null != jsonArray ){
source.setReadScopeList( toAccountNameList( jsonArray ));
}
}