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


Java JsonObject.getAsJsonArray方法代码示例

本文整理汇总了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);
        }
    }
}
 
开发者ID:WarzoneMC,项目名称:Warzone,代码行数:27,代码来源:SpawnPointLoaderModule.java

示例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);
			}
		}
	}
}
 
开发者ID:Gurgy,项目名称:Cypher,代码行数:25,代码来源:Room.java

示例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;
}
 
开发者ID:PhoenixDevTeam,项目名称:Phoenix-for-VK,代码行数:21,代码来源:FeedbackUserArrayDtoAdapter.java

示例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();
}
 
开发者ID:mezau532,项目名称:smart_commuter,代码行数:17,代码来源:GoogleGeocodeSync.java

示例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;
    }
}
 
开发者ID:kacperduras,项目名称:Charrizard,代码行数:35,代码来源:SkriptServerResponse.java

示例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;
}
 
开发者ID:dreaminglion,项目名称:iosched-reader,代码行数:10,代码来源:DataExtractor.java

示例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();
}
 
开发者ID:Xianguang-Zhou,项目名称:smartqq-client,代码行数:15,代码来源:Message.java

示例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;
}
 
开发者ID:PhoenixDevTeam,项目名称:Phoenix-for-VK,代码行数:44,代码来源:PhotoAlbumDtoAdapter.java

示例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;
}
 
开发者ID:xiaomin0322,项目名称:marathon-auth-plugin,代码行数:66,代码来源:HTTPAuthFilter.java

示例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();
    }
}
 
开发者ID:eltrueno,项目名称:TruenoNPC,代码行数:39,代码来源:TruenoNPC_v1_12_r1.java

示例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);
  }
}
 
开发者ID:mit-ll,项目名称:PACE,代码行数:39,代码来源:VersioningIT.java

示例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());
    }
}
 
开发者ID:SamaGames,项目名称:Hydroangeas,代码行数:11,代码来源:PackageGameTemplate.java

示例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;
}
 
开发者ID:eltrueno,项目名称:TruenoNPC,代码行数:16,代码来源:TruenoNPC_v1_9_r2.java

示例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;
}
 
开发者ID:CMPUT301F17T17,项目名称:Habitizer,代码行数:41,代码来源:ElasticsearchController.java

示例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 ));
    }
}
 
开发者ID:mithrilcoin-io,项目名称:EosCommander,代码行数:15,代码来源:SignedTransaction.java


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