本文整理汇总了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;
}
示例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;
}
示例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]);
}
}
示例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());
}
}
示例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]);
}
}
示例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);
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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<>();
}
}
}
示例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]);
}
}
}
示例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;
}
示例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;
}
示例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;
}