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


Java JsonArray.size方法代码示例

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


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

示例1: parseFloatArray

import com.google.gson.JsonArray; //导入方法依赖的package包/类
public static float[] parseFloatArray(JsonElement e, int length, String prefix)
{
    if (!e.isJsonArray()) throw new JsonParseException(prefix + ": expected an array, got: " + e);
    JsonArray t = e.getAsJsonArray();
    if (t.size() != length) throw new JsonParseException(prefix + ": expected an array of length " + length + ", got: " + t.size());
    float[] ret = new float[length];
    for (int i = 0; i < length; i++)
    {
        try
        {
            ret[i] = t.get(i).getAsNumber().floatValue();
        }
        catch (ClassCastException ex)
        {
            throw new JsonParseException(prefix + " element: expected number, got: " + t.get(i));
        }
    }
    return ret;
}
 
开发者ID:F1r3w477,项目名称:CustomWorldGen,代码行数:20,代码来源:ForgeBlockStateV1.java

示例2: deserialize

import com.google.gson.JsonArray; //导入方法依赖的package包/类
public ServerStatusResponse.Players deserialize(JsonElement p_deserialize_1_, Type p_deserialize_2_, JsonDeserializationContext p_deserialize_3_) throws JsonParseException
{
    JsonObject jsonobject = JsonUtils.getJsonObject(p_deserialize_1_, "players");
    ServerStatusResponse.Players serverstatusresponse$players = new ServerStatusResponse.Players(JsonUtils.getInt(jsonobject, "max"), JsonUtils.getInt(jsonobject, "online"));

    if (JsonUtils.isJsonArray(jsonobject, "sample"))
    {
        JsonArray jsonarray = JsonUtils.getJsonArray(jsonobject, "sample");

        if (jsonarray.size() > 0)
        {
            GameProfile[] agameprofile = new GameProfile[jsonarray.size()];

            for (int i = 0; i < agameprofile.length; ++i)
            {
                JsonObject jsonobject1 = JsonUtils.getJsonObject(jsonarray.get(i), "player[" + i + "]");
                String s = JsonUtils.getString(jsonobject1, "id");
                agameprofile[i] = new GameProfile(UUID.fromString(s), JsonUtils.getString(jsonobject1, "name"));
            }

            serverstatusresponse$players.setPlayers(agameprofile);
        }
    }

    return serverstatusresponse$players;
}
 
开发者ID:F1r3w477,项目名称:CustomWorldGen,代码行数:27,代码来源:ServerStatusResponse.java

示例3: parsePosition

import com.google.gson.JsonArray; //导入方法依赖的package包/类
private Vector3f parsePosition(JsonObject p_178251_1_, String p_178251_2_)
{
    JsonArray jsonarray = JsonUtils.getJsonArray(p_178251_1_, p_178251_2_);

    if (jsonarray.size() != 3)
    {
        throw new JsonParseException("Expected 3 " + p_178251_2_ + " values, found: " + jsonarray.size());
    }
    else
    {
        float[] afloat = new float[3];

        for (int i = 0; i < afloat.length; ++i)
        {
            afloat[i] = JsonUtils.getFloat(jsonarray.get(i), p_178251_2_ + "[" + i + "]");
        }

        return new Vector3f(afloat[0], afloat[1], afloat[2]);
    }
}
 
开发者ID:SkidJava,项目名称:BaseClient,代码行数:21,代码来源:BlockPart.java

示例4: loadConfiguration

import com.google.gson.JsonArray; //导入方法依赖的package包/类
@Override
public void loadConfiguration(JsonArray rootJson)
{
    if (rootJson.size() == 0)
        return;

    for (int i = 0; i < rootJson.size(); i++)
    {
        JsonObject graouJson = rootJson.get(i).getAsJsonObject();

        Location catLocation = LocationUtils.str2loc(graouJson.get("cat").getAsString());
        Location doorLocation = LocationUtils.str2loc(graouJson.get("door").getAsString());
        Location treasureLocation = LocationUtils.str2loc(graouJson.get("treasure").getAsString());
        Location openingLocation = LocationUtils.str2loc(graouJson.get("opening").getAsString());

        Graou graou = new Graou(this.hub, catLocation, doorLocation, treasureLocation, openingLocation);

        this.interactions.add(graou);
        this.log(Level.INFO, "Registered Graou at '" + graouJson.get("cat").getAsString());
    }
}
 
开发者ID:SamaGames,项目名称:Hub,代码行数:22,代码来源:GraouManager.java

示例5: parsePosition

import com.google.gson.JsonArray; //导入方法依赖的package包/类
private Vector3f parsePosition(JsonObject object, String memberName)
{
    JsonArray jsonarray = JsonUtils.getJsonArray(object, memberName);

    if (jsonarray.size() != 3)
    {
        throw new JsonParseException("Expected 3 " + memberName + " values, found: " + jsonarray.size());
    }
    else
    {
        float[] afloat = new float[3];

        for (int i = 0; i < afloat.length; ++i)
        {
            afloat[i] = JsonUtils.getFloat(jsonarray.get(i), memberName + "[" + i + "]");
        }

        return new Vector3f(afloat[0], afloat[1], afloat[2]);
    }
}
 
开发者ID:F1r3w477,项目名称:CustomWorldGen,代码行数:21,代码来源:BlockPart.java

示例6: deserialize

import com.google.gson.JsonArray; //导入方法依赖的package包/类
@Override
public Template deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context)
		throws JsonParseException {
	if (!json.isJsonArray()) {
		throw new JsonParseException("Unexpected JsonElement!");
	}
	JsonArray jsa = (JsonArray) json;
	jSonUtils utils = jSonUtils.getInstance();
	TemplateField[] data = new TemplateField[jsa.size()];
	for (int i = 0; i < jsa.size(); i++) {
		try {
			data[i] = utils.templateFromJSon(jsa.get(i), context);
		} catch (ClassCastException e) {
			throw new JsonParseException(e);
		}
	}
	return new Template(data);
}
 
开发者ID:pSpaces,项目名称:jSpace,代码行数:19,代码来源:TemplateDeserializer.java

示例7: nameHistoryFromUuid

import com.google.gson.JsonArray; //导入方法依赖的package包/类
public static List<String> nameHistoryFromUuid(UUID uuid)
{
    URLConnection connection;
    try
    {
        connection = new URL("https://api.mojang.com/user/profiles/"
                + uuid.toString().replace("-", "").toLowerCase() + "/names"
        ).openConnection();
        String text = new Scanner(connection.getInputStream(), "UTF-8").useDelimiter("\\Z").next();
        JsonArray list = (JsonArray) parser.parse(text);
        List<String> names = new ArrayList<>();
        for (int i = 0; i < list.size(); i++)
            names.add(((JsonObject) list.get(i)).get("name").getAsString());
        return names;
    } catch (IOException e)
    {
        e.printStackTrace();
    }
    return null;
}
 
开发者ID:SamaGames,项目名称:SamaGamesCore,代码行数:21,代码来源:NameFetcher.java

示例8: deserialize

import com.google.gson.JsonArray; //导入方法依赖的package包/类
@Override
public MultiLineStringDto deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) {

	MultiLineStringDto dto = new MultiLineStringDto();
	List<LineStringDto> lines = new ArrayList<>();
	dto.setLines(lines);

	JsonObject asJsonObject = json.getAsJsonObject();
	JsonArray jsonArray = asJsonObject.get("coordinates").getAsJsonArray();
	Type positionCollectionType = new TypeToken<List<PositionDto>>() {
	}.getType();
	for (int i = 0; i < jsonArray.size(); i++) {
		List<PositionDto> positions = context.deserialize(jsonArray.get(i), positionCollectionType);
		LineStringDto line = new LineStringDto();
		line.setPositions(positions);
		lines.add(line);
	}

	dto.setBbox(BoundingBoxParser.parseBbox(asJsonObject, context));
	
	return dto;
}
 
开发者ID:mokszr,项目名称:ultimate-geojson,代码行数:23,代码来源:MultiLineStringDeserializer.java

示例9: isVideoResult

import com.google.gson.JsonArray; //导入方法依赖的package包/类
/** Returns true if the result JSON is for video. */
private static boolean isVideoResult(JsonObject result) {
  if (result.get("tag") != null && result.get("tag").isJsonObject()) {
    JsonElement timestamps = result.get("tag").getAsJsonObject().get("timestamps");
    if (timestamps != null && timestamps.isJsonArray()) {
      return true;
    }
  }
  if (result.get("embed") != null && result.get("embed").isJsonArray()) {
    JsonArray embedArray = result.get("embed").getAsJsonArray();
    if (embedArray.size() > 0 && embedArray.get(0).isJsonArray()) {
      return true;
    }
  }
  return false;
}
 
开发者ID:Kitt3120,项目名称:ViperBot,代码行数:17,代码来源:RecognitionResult.java

示例10: parseIntArray

import com.google.gson.JsonArray; //导入方法依赖的package包/类
protected static int[] parseIntArray(JsonArray array){
    int[] list = new int[array.size()];
    for(int i = 0; i < array.size(); i++){
        list[i] = array.get(i).getAsInt();
    }

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

示例11: postLogin

import com.google.gson.JsonArray; //导入方法依赖的package包/类
/**
 * Checks if network is available and gets habits accordingly
 * @param username
 */
private void postLogin(String username) {
    Type listType;
    if(Utilities.isNetworkAvailable(LoginActivity.this)){
        ElasticsearchController.GetItemsTask getHabitsArrayGetTask = new ElasticsearchController.GetItemsTask();
        getHabitsArrayGetTask.execute(DummyMainActivity.Habit_Index, "username", username);
        try{
            JsonArray jsonHabits =  getHabitsArrayGetTask.get();
            DummyMainActivity.myHabits = new ArrayList<>();
            for (int i = 0; i < jsonHabits.size(); i++){
                Habit h = new Habit();
                JsonObject job  = jsonHabits.get(i).getAsJsonObject();
                h.fromJsonObject(job);
                DummyMainActivity.myHabits.add(h);
            }
        }catch (Exception e){
            Log.d("ESC", "Adding habits in login.");
        }
    }else{

        listType = new TypeToken<ArrayList<Habit>>(){}.getType();
        DummyMainActivity.myHabits =  FileController.loadFromFile(LoginActivity.this, DummyMainActivity.HABITFILENAME, listType);
        if ( DummyMainActivity.myHabits == null){
            DummyMainActivity.myHabits = new ArrayList<>();
        }
    }
}
 
开发者ID:CMPUT301F17T17,项目名称:Habitizer,代码行数:31,代码来源:LoginActivity.java

示例12: parseVector3f

import com.google.gson.JsonArray; //导入方法依赖的package包/类
private Vector3f parseVector3f(JsonObject jsonObject, String key, Vector3f defaultValue)
{
    if (!jsonObject.has(key))
    {
        return defaultValue;
    }
    else
    {
        JsonArray jsonarray = JsonUtils.getJsonArray(jsonObject, key);

        if (jsonarray.size() != 3)
        {
            throw new JsonParseException("Expected 3 " + key + " values, found: " + jsonarray.size());
        }
        else
        {
            float[] afloat = new float[3];

            for (int i = 0; i < afloat.length; ++i)
            {
                afloat[i] = JsonUtils.getFloat(jsonarray.get(i), key + "[" + i + "]");
            }

            return new Vector3f(afloat[0], afloat[1], afloat[2]);
        }
    }
}
 
开发者ID:F1r3w477,项目名称:CustomWorldGen,代码行数:28,代码来源:ItemTransformVec3f.java

示例13: getConvertedArrayToString

import com.google.gson.JsonArray; //导入方法依赖的package包/类
private String getConvertedArrayToString(JsonArray array) {
	String string = "";
	for (int i = 0; i < array.size(); i++)
		string += (i == array.size() - 1) ? array.get(i).getAsString() : array.get(i).getAsString() + ", ";

	return string;
}
 
开发者ID:capitalone,项目名称:Hydrograph,代码行数:8,代码来源:LingualSchemaCreatorTest.java

示例14: read

import com.google.gson.JsonArray; //导入方法依赖的package包/类
/**
 * Read the encryption key container from the reader.
 *
 * @param in
 *          Input reader.
 * @return Parsed encryption key container.
 */
public static LocalEncryptionKeyContainer read(Reader in) {
  LocalEncryptionKeyContainer container = new LocalEncryptionKeyContainer();
  JsonParser parser = new JsonParser();

  JsonObject data = parser.parse(in).getAsJsonObject();
  int version = data.getAsJsonPrimitive("version").getAsInt();

  switch (version) {
    case 1:
      JsonArray keys = data.getAsJsonArray("keys");
      for (int i = 0; i < keys.size(); i++) {
        JsonObject key = keys.get(i).getAsJsonObject();
        if (key.has("attribute")) {
          container.addKey(key.getAsJsonPrimitive("attribute").getAsString(), key.getAsJsonPrimitive("id").getAsString(), key.getAsJsonPrimitive("version")
              .getAsInt(), Base64.getDecoder().decode(key.getAsJsonPrimitive("key").getAsString()), false);
        } else {
          container.addKey(null, key.getAsJsonPrimitive("id").getAsString(), key.getAsJsonPrimitive("version").getAsInt(),
              Base64.getDecoder().decode(key.getAsJsonPrimitive("key").getAsString()), false);
        }
      }
      break;

    default:
      throw new UnsupportedOperationException("unsupported file version");
  }

  return container;
}
 
开发者ID:mit-ll,项目名称:PACE,代码行数:36,代码来源:LocalEncryptionKeyContainer.java

示例15: deserialize

import com.google.gson.JsonArray; //导入方法依赖的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


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