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


Java JsonArray.get方法代码示例

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


在下文中一共展示了JsonArray.get方法的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: parseAddress

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

示例3: parseLocation

import com.google.gson.JsonArray; //导入方法依赖的package包/类
public LocationDTO parseLocation(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();
    JsonObject ob2 = obj.getAsJsonObject("geometry");
    JsonObject obj3 = ob2.getAsJsonObject("location");
    String jsonString = obj3.toString();

    Gson gson = new GsonBuilder().create();
    LocationDTO loc = gson.fromJson(jsonString, LocationDTO.class);

    return loc;
}
 
开发者ID:mezau532,项目名称:smart_commuter,代码行数:23,代码来源:GoogleGeocodeSync.java

示例4: loadConfiguration

import com.google.gson.JsonArray; //导入方法依赖的package包/类
@Override
public void loadConfiguration(JsonArray rootJson)
{
    for (int i = 0; i < rootJson.size(); i++)
    {
        JsonElement jsonBumber = rootJson.get(i);

        Bumper bumper = null;

        try
        {
            bumper = new Bumper(this.hub, jsonBumber.getAsString());
        }
        catch (Exception ignored) {}

        if (bumper != null)
        {
            this.interactions.add(bumper);
            this.log(Level.INFO, "Registered bumper at '" + jsonBumber.getAsString());
        }
    }
}
 
开发者ID:SamaGames,项目名称:Hub,代码行数:23,代码来源:BumperManager.java

示例5: getElement

import com.google.gson.JsonArray; //导入方法依赖的package包/类
@Nullable
private JsonElement getElement(JsonElement element, String key)
{
    if (key.isEmpty())
    {
        return element;
    }
    if (element.isJsonArray())
    {
        JsonArray jsonArray = element.getAsJsonArray();
        int i = DioriteMathUtils.asInt(key, - 1);
        if ((i == - 1) || (i < jsonArray.size()))
        {
            return null;
        }
        return jsonArray.get(i);
    }
    if (element.isJsonObject())
    {
        return element.getAsJsonObject().get(key);
    }
    return null;
}
 
开发者ID:GotoFinal,项目名称:diorite-configs-java8,代码行数:24,代码来源:JsonDeserializationData.java

示例6: analysisJsonStr

import com.google.gson.JsonArray; //导入方法依赖的package包/类
private void analysisJsonStr(StringBuilder sb, Object json) {
    LinkedHashMap<Object, Object> map = new LinkedHashMap<>();
    Object jo = json;
    if (jo instanceof JsonObject) {
        FileUtil.analysisJson(map, (JsonObject) jo, "");
    } else if (jo instanceof JsonArray) {
        JsonArray ja = (JsonArray) jo;
        Object subjo = ja.get(0);
        if (subjo instanceof JsonObject) {
            FileUtil.analysisJson(map, (JsonObject) subjo, "");
        }
    } else {
        sb.append("**result有误").append(jo);
    }
    analysisMap(map, sb, "");
}
 
开发者ID:ajtdnyy,项目名称:PackagePlugin,代码行数:17,代码来源:MainFrame.java

示例7: deserializeSounds

import com.google.gson.JsonArray; //导入方法依赖的package包/类
private List<Sound> deserializeSounds(JsonObject object)
{
    List<Sound> list = Lists.<Sound>newArrayList();

    if (object.has("sounds"))
    {
        JsonArray jsonarray = JsonUtils.getJsonArray(object, "sounds");

        for (int i = 0; i < jsonarray.size(); ++i)
        {
            JsonElement jsonelement = jsonarray.get(i);

            if (JsonUtils.isString(jsonelement))
            {
                String s = JsonUtils.getString(jsonelement, "sound");
                list.add(new Sound(s, 1.0F, 1.0F, 1, Sound.Type.FILE, false));
            }
            else
            {
                list.add(this.deserializeSound(JsonUtils.getJsonObject(jsonelement, "sound")));
            }
        }
    }

    return list;
}
 
开发者ID:sudofox,项目名称:Backmemed,代码行数:27,代码来源:SoundListSerializer.java

示例8: fromJsonArray

import com.google.gson.JsonArray; //导入方法依赖的package包/类
@Override
Option<?> fromJsonArray(JsonArray arr, Type type, Type[] subTypes, JsonDeserializationContext ctx) throws JsonParseException {
    if (arr.size() < 1 || arr.size() > 2) {
        throw new JsonParseException("bad json format");
    }
    String status = arr.get(0).getAsString();
    if ("defined".equals(status)) {
        if (arr.size() == 2) {
            Object el = subTypes.length > 0 ? ctx.deserialize(arr.get(1), subTypes[0]) : arr.get(1);
            return Option.some(el);
        } else {
            throw new JsonParseException("expected array size: 2");
        }
    } else {
        return Option.none();
    }
}
 
开发者ID:vavr-io,项目名称:vavr-gson,代码行数:18,代码来源:OptionConverter.java

示例9: jsonToKeypoints

import com.google.gson.JsonArray; //导入方法依赖的package包/类
public static MatOfKeyPoint jsonToKeypoints(String json){
    MatOfKeyPoint result = new MatOfKeyPoint();

    JsonParser parser = new JsonParser();
    JsonArray jsonArr = parser.parse(json).getAsJsonArray();

    int size = jsonArr.size();

    KeyPoint[] kpArray = new KeyPoint[size];

    for(int i=0; i<size; i++){
        KeyPoint kp = new KeyPoint();

        JsonObject obj = (JsonObject) jsonArr.get(i);

        kp.pt = new Point(
                obj.get("x").getAsDouble(),
                obj.get("y").getAsDouble()
        );
        kp.class_id = obj.get("class_id").getAsInt();
        kp.size = obj.get("size").getAsFloat();
        kp.angle = obj.get("angle").getAsFloat();
        kp.octave = obj.get("octave").getAsInt();
        kp.response = obj.get("response").getAsFloat();

        kpArray[i] = kp;
    }

    result.fromArray(kpArray);

    return result;
}
 
开发者ID:jorenham,项目名称:fingerblox,代码行数:33,代码来源:ImageDisplayActivity.java

示例10: fromJsonArray

import com.google.gson.JsonArray; //导入方法依赖的package包/类
@Override
Tuple fromJsonArray(JsonArray json, Type type, Type[] subTypes, JsonDeserializationContext ctx) {
    if (subTypes.length > 0 && json.size() != subTypes.length) {
        throw new JsonParseException("elements expected: " + subTypes.length);
    }
    Object[] arr = new Object[json.size()];
    for (int i = 0; i < json.size(); i++) {
        JsonElement el = json.get(i);
        arr[i] = subTypes.length > 0 ? ctx.deserialize(el, subTypes[i]) : el;
    }
    switch (json.size()) {
        case 0:
            return Tuple0.instance();
        case 1:
            return Tuple.of(arr[0]);
        case 2:
            return Tuple.of(arr[0], arr[1]);
        case 3:
            return Tuple.of(arr[0], arr[1], arr[2]);
        case 4:
            return Tuple.of(arr[0], arr[1], arr[2], arr[3]);
        case 5:
            return Tuple.of(arr[0], arr[1], arr[2], arr[3], arr[4]);
        case 6:
            return Tuple.of(arr[0], arr[1], arr[2], arr[3], arr[4], arr[5]);
        case 7:
            return Tuple.of(arr[0], arr[1], arr[2], arr[3], arr[4], arr[5], arr[6]);
        case 8:
            return Tuple.of(arr[0], arr[1], arr[2], arr[3], arr[4], arr[5], arr[6], arr[7]);
        default:
            throw new JsonParseException("bad tuple arity");
    }
}
 
开发者ID:vavr-io,项目名称:vavr-gson,代码行数:34,代码来源:TupleConverter.java

示例11: keypointsFromJson

import com.google.gson.JsonArray; //导入方法依赖的package包/类
public static MatOfKeyPoint keypointsFromJson(String json){
    MatOfKeyPoint result = new MatOfKeyPoint();

    JsonParser parser = new JsonParser();
    JsonArray jsonArr = parser.parse(json).getAsJsonArray();        

    int size = jsonArr.size();

    KeyPoint[] kpArray = new KeyPoint[size];

    for(int i=0; i<size; i++){
        KeyPoint kp = new KeyPoint(); 

        JsonObject obj = (JsonObject) jsonArr.get(i);

        Point point = new Point( 
                obj.get("x").getAsDouble(), 
                obj.get("y").getAsDouble() 
        );          

        kp.pt       = point;
        kp.class_id = obj.get("class_id").getAsInt();
        kp.size     =     obj.get("size").getAsFloat();
        kp.angle    =    obj.get("angle").getAsFloat();
        kp.octave   =   obj.get("octave").getAsInt();
        kp.response = obj.get("response").getAsFloat();

        kpArray[i] = kp;
    }

    result.fromArray(kpArray);

    return result;
}
 
开发者ID:fossasia,项目名称:zooracle,代码行数:35,代码来源:OpenCVUtils.java

示例12: parseEntityRender

import com.google.gson.JsonArray; //导入方法依赖的package包/类
public static CustomEntityRenderer parseEntityRender(JsonObject obj, String path)
{
    ConnectedParser connectedparser = new ConnectedParser("CustomEntityModels");
    String s = connectedparser.parseName(path);
    String s1 = connectedparser.parseBasePath(path);
    String s2 = Json.getString(obj, "texture");
    int[] aint = Json.parseIntArray(obj.get("textureSize"), 2);
    float f = Json.getFloat(obj, "shadowSize", -1.0F);
    JsonArray jsonarray = (JsonArray)obj.get("models");
    checkNull(jsonarray, "Missing models");
    Map map = new HashMap();
    List list = new ArrayList();

    for (int i = 0; i < jsonarray.size(); ++i)
    {
        JsonObject jsonobject = (JsonObject)jsonarray.get(i);
        processBaseId(jsonobject, map);
        processExternalModel(jsonobject, map, s1);
        processId(jsonobject, map);
        CustomModelRenderer custommodelrenderer = parseCustomModelRenderer(jsonobject, aint, s1);

        if (custommodelrenderer != null)
        {
            list.add(custommodelrenderer);
        }
    }

    CustomModelRenderer[] acustommodelrenderer = (CustomModelRenderer[])((CustomModelRenderer[])list.toArray(new CustomModelRenderer[list.size()]));
    ResourceLocation resourcelocation = null;

    if (s2 != null)
    {
        resourcelocation = getResourceLocation(s1, s2, ".png");
    }

    CustomEntityRenderer customentityrenderer = new CustomEntityRenderer(s, s1, resourcelocation, acustommodelrenderer, f);
    return customentityrenderer;
}
 
开发者ID:sudofox,项目名称:Backmemed,代码行数:39,代码来源:CustomEntityModelParser.java

示例13: deserialize

import com.google.gson.JsonArray; //导入方法依赖的package包/类
public AnimationMetadataSection deserialize(JsonElement p_deserialize_1_, Type p_deserialize_2_, JsonDeserializationContext p_deserialize_3_) throws JsonParseException
{
    List<AnimationFrame> list = Lists.<AnimationFrame>newArrayList();
    JsonObject jsonobject = JsonUtils.getJsonObject(p_deserialize_1_, "metadata section");
    int i = JsonUtils.getInt(jsonobject, "frametime", 1);

    if (i != 1)
    {
        Validate.inclusiveBetween(1L, 2147483647L, (long)i, "Invalid default frame time");
    }

    if (jsonobject.has("frames"))
    {
        try
        {
            JsonArray jsonarray = JsonUtils.getJsonArray(jsonobject, "frames");

            for (int j = 0; j < jsonarray.size(); ++j)
            {
                JsonElement jsonelement = jsonarray.get(j);
                AnimationFrame animationframe = this.parseAnimationFrame(j, jsonelement);

                if (animationframe != null)
                {
                    list.add(animationframe);
                }
            }
        }
        catch (ClassCastException classcastexception)
        {
            throw new JsonParseException("Invalid animation->frames: expected array, was " + jsonobject.get("frames"), classcastexception);
        }
    }

    int k = JsonUtils.getInt(jsonobject, "width", -1);
    int l = JsonUtils.getInt(jsonobject, "height", -1);

    if (k != -1)
    {
        Validate.inclusiveBetween(1L, 2147483647L, (long)k, "Invalid width");
    }

    if (l != -1)
    {
        Validate.inclusiveBetween(1L, 2147483647L, (long)l, "Invalid height");
    }

    boolean flag = JsonUtils.getBoolean(jsonobject, "interpolate", false);
    return new AnimationMetadataSection(list, k, l, i, flag);
}
 
开发者ID:F1r3w477,项目名称:CustomWorldGen,代码行数:51,代码来源:AnimationMetadataSectionSerializer.java

示例14: deserialize

import com.google.gson.JsonArray; //导入方法依赖的package包/类
public SoundList deserialize(JsonElement p_deserialize_1_, Type p_deserialize_2_, JsonDeserializationContext p_deserialize_3_) throws JsonParseException
{
    JsonObject jsonobject = JsonUtils.getJsonObject(p_deserialize_1_, "entry");
    SoundList soundlist = new SoundList();
    soundlist.setReplaceExisting(JsonUtils.getBoolean(jsonobject, "replace", false));
    SoundCategory soundcategory = SoundCategory.getCategory(JsonUtils.getString(jsonobject, "category", SoundCategory.MASTER.getCategoryName()));
    soundlist.setSoundCategory(soundcategory);
    Validate.notNull(soundcategory, "Invalid category", new Object[0]);

    if (jsonobject.has("sounds"))
    {
        JsonArray jsonarray = JsonUtils.getJsonArray(jsonobject, "sounds");

        for (int i = 0; i < jsonarray.size(); ++i)
        {
            JsonElement jsonelement = jsonarray.get(i);
            SoundList.SoundEntry soundlist$soundentry = new SoundList.SoundEntry();

            if (JsonUtils.isString(jsonelement))
            {
                soundlist$soundentry.setSoundEntryName(JsonUtils.getString(jsonelement, "sound"));
            }
            else
            {
                JsonObject jsonobject1 = JsonUtils.getJsonObject(jsonelement, "sound");
                soundlist$soundentry.setSoundEntryName(JsonUtils.getString(jsonobject1, "name"));

                if (jsonobject1.has("type"))
                {
                    SoundList.SoundEntry.Type soundlist$soundentry$type = SoundList.SoundEntry.Type.getType(JsonUtils.getString(jsonobject1, "type"));
                    Validate.notNull(soundlist$soundentry$type, "Invalid type", new Object[0]);
                    soundlist$soundentry.setSoundEntryType(soundlist$soundentry$type);
                }

                if (jsonobject1.has("volume"))
                {
                    float f = JsonUtils.getFloat(jsonobject1, "volume");
                    Validate.isTrue(f > 0.0F, "Invalid volume", new Object[0]);
                    soundlist$soundentry.setSoundEntryVolume(f);
                }

                if (jsonobject1.has("pitch"))
                {
                    float f1 = JsonUtils.getFloat(jsonobject1, "pitch");
                    Validate.isTrue(f1 > 0.0F, "Invalid pitch", new Object[0]);
                    soundlist$soundentry.setSoundEntryPitch(f1);
                }

                if (jsonobject1.has("weight"))
                {
                    int j = JsonUtils.getInt(jsonobject1, "weight");
                    Validate.isTrue(j > 0, "Invalid weight", new Object[0]);
                    soundlist$soundentry.setSoundEntryWeight(j);
                }

                if (jsonobject1.has("stream"))
                {
                    soundlist$soundentry.setStreaming(JsonUtils.getBoolean(jsonobject1, "stream"));
                }
            }

            soundlist.getSoundList().add(soundlist$soundentry);
        }
    }

    return soundlist;
}
 
开发者ID:Notoh,项目名称:DecompiledMinecraft,代码行数:68,代码来源:SoundListSerializer.java

示例15: parseItemModel

import com.google.gson.JsonArray; //导入方法依赖的package包/类
public static PlayerItemModel parseItemModel(JsonObject p_parseItemModel_0_)
{
    String s = Json.getString(p_parseItemModel_0_, "type");

    if (!Config.equals(s, "PlayerItem"))
    {
        throw new JsonParseException("Unknown model type: " + s);
    }
    else
    {
        int[] aint = Json.parseIntArray(p_parseItemModel_0_.get("textureSize"), 2);
        checkNull(aint, "Missing texture size");
        Dimension dimension = new Dimension(aint[0], aint[1]);
        boolean flag = Json.getBoolean(p_parseItemModel_0_, "usePlayerTexture", false);
        JsonArray jsonarray = (JsonArray)p_parseItemModel_0_.get("models");
        checkNull(jsonarray, "Missing elements");
        Map map = new HashMap();
        List list = new ArrayList();
        new ArrayList();

        for (int i = 0; i < jsonarray.size(); ++i)
        {
            JsonObject jsonobject = (JsonObject)jsonarray.get(i);
            String s1 = Json.getString(jsonobject, "baseId");

            if (s1 != null)
            {
                JsonObject jsonobject1 = (JsonObject)map.get(s1);

                if (jsonobject1 == null)
                {
                    Config.warn("BaseID not found: " + s1);
                    continue;
                }

                for (Entry<String, JsonElement> entry : jsonobject1.entrySet())
                {
                    if (!jsonobject.has((String)entry.getKey()))
                    {
                        jsonobject.add((String)entry.getKey(), (JsonElement)entry.getValue());
                    }
                }
            }

            String s2 = Json.getString(jsonobject, "id");

            if (s2 != null)
            {
                if (!map.containsKey(s2))
                {
                    map.put(s2, jsonobject);
                }
                else
                {
                    Config.warn("Duplicate model ID: " + s2);
                }
            }

            PlayerItemRenderer playeritemrenderer = parseItemRenderer(jsonobject, dimension);

            if (playeritemrenderer != null)
            {
                list.add(playeritemrenderer);
            }
        }

        PlayerItemRenderer[] aplayeritemrenderer = (PlayerItemRenderer[])((PlayerItemRenderer[])list.toArray(new PlayerItemRenderer[list.size()]));
        return new PlayerItemModel(dimension, flag, aplayeritemrenderer);
    }
}
 
开发者ID:SkidJava,项目名称:BaseClient,代码行数:71,代码来源:PlayerItemParser.java


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