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


Java JsonSyntaxException类代码示例

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


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

示例1: deserialize

import com.google.gson.JsonSyntaxException; //导入依赖的package包/类
public LootCondition deserialize(JsonElement p_deserialize_1_, Type p_deserialize_2_, JsonDeserializationContext p_deserialize_3_) throws JsonParseException
{
    JsonObject jsonobject = JsonUtils.getJsonObject(p_deserialize_1_, "condition");
    ResourceLocation resourcelocation = new ResourceLocation(JsonUtils.getString(jsonobject, "condition"));
    LootCondition.Serializer<?> serializer;

    try
    {
        serializer = LootConditionManager.getSerializerForName(resourcelocation);
    }
    catch (IllegalArgumentException var8)
    {
        throw new JsonSyntaxException("Unknown condition \'" + resourcelocation + "\'");
    }

    return serializer.deserialize(jsonobject, p_deserialize_3_);
}
 
开发者ID:sudofox,项目名称:Backmemed,代码行数:18,代码来源:LootConditionManager.java

示例2: deserialize

import com.google.gson.JsonSyntaxException; //导入依赖的package包/类
public SetAttributes deserialize(JsonObject object, JsonDeserializationContext deserializationContext, LootCondition[] conditionsIn)
{
    JsonArray jsonarray = JsonUtils.getJsonArray(object, "modifiers");
    SetAttributes.Modifier[] asetattributes$modifier = new SetAttributes.Modifier[jsonarray.size()];
    int i = 0;

    for (JsonElement jsonelement : jsonarray)
    {
        asetattributes$modifier[i++] = SetAttributes.Modifier.deserialize(JsonUtils.getJsonObject(jsonelement, "modifier"), deserializationContext);
    }

    if (asetattributes$modifier.length == 0)
    {
        throw new JsonSyntaxException("Invalid attribute modifiers array; cannot be empty");
    }
    else
    {
        return new SetAttributes(conditionsIn, asetattributes$modifier);
    }
}
 
开发者ID:F1r3w477,项目名称:CustomWorldGen,代码行数:21,代码来源:SetAttributes.java

示例3: getDeploymentEvents

import com.google.gson.JsonSyntaxException; //导入依赖的package包/类
private List<CMSEvent> getDeploymentEvents() {
    List<CMSEvent> events = new ArrayList<>();
    try {
        InputStream is = this.getClass().getClassLoader().getResourceAsStream("deployment-events.txt");
        BufferedReader reader = new BufferedReader(new InputStreamReader(is));
        String line = reader.readLine();
        while (line != null) {
            CMSEvent event = new CMSEvent();
            event.addHeaders("sourceId", "546589");
            event.addHeaders("action", "update");
            event.addHeaders("source", "deployment");
            event.addHeaders("clazzName", "Deployment");
            CmsDeployment deployment = gson.fromJson(line, CmsDeployment.class);
            event.setPayload(deployment);
            events.add(event);
            line = reader.readLine();
        }
    } catch (JsonSyntaxException | IOException e) {
        e.printStackTrace();
    }
    return events;
}
 
开发者ID:oneops,项目名称:oneops,代码行数:23,代码来源:MessagePublisherTest.java

示例4: getGridOfWeek

import com.google.gson.JsonSyntaxException; //导入依赖的package包/类
/**
 * Получение недельной таблици с данными для предварительной записи.
 *
 * @param netProperty netProperty параметры соединения с сервером.
 * @param serviceId услуга, в которую пытаемся встать.
 * @param date первый день недели за которую нужны данные.
 * @param advancedCustomer ID авторизованного кастомера
 * @return класс с параметрами и списком времен
 */
public static RpcGetGridOfWeek.GridAndParams getGridOfWeek(INetProperty netProperty,
    long serviceId, Date date, long advancedCustomer) {
    QLog.l().logger().info("Получить таблицу");
    // загрузим ответ
    final CmdParams params = new CmdParams();
    params.serviceId = serviceId;
    params.date = date.getTime();
    params.customerId = advancedCustomer;
    final String res;
    try {
        res = send(netProperty, Uses.TASK_GET_GRID_OF_WEEK, params);
    } catch (QException e) {// вывод исключений
        throw new ClientException(Locales.locMes("command_error2"), e);
    }
    final Gson gson = GsonPool.getInstance().borrowGson();
    final RpcGetGridOfWeek rpc;
    try {
        rpc = gson.fromJson(res, RpcGetGridOfWeek.class);
    } catch (JsonSyntaxException ex) {
        throw new ClientException(Locales.locMes("bad_response") + "\n" + ex.toString());
    } finally {
        GsonPool.getInstance().returnGson(gson);
    }
    return rpc.getResult();
}
 
开发者ID:bcgov,项目名称:sbc-qsystem,代码行数:35,代码来源:NetCommander.java

示例5: parse

import com.google.gson.JsonSyntaxException; //导入依赖的package包/类
public static JsonElement parse(JsonReader reader) throws JsonParseException {
    boolean isEmpty = true;
    try {
        reader.peek();
        isEmpty = false;
        return (JsonElement) TypeAdapters.JSON_ELEMENT.read(reader);
    } catch (Throwable e) {
        if (isEmpty) {
            return JsonNull.INSTANCE;
        }
        throw new JsonIOException(e);
    } catch (Throwable e2) {
        throw new JsonSyntaxException(e2);
    } catch (Throwable e22) {
        throw new JsonIOException(e22);
    } catch (Throwable e222) {
        throw new JsonSyntaxException(e222);
    }
}
 
开发者ID:JackChan1999,项目名称:letv,代码行数:20,代码来源:Streams.java

示例6: readGeneric

import com.google.gson.JsonSyntaxException; //导入依赖的package包/类
public static int readGeneric(File f) {
    int count = 0;
    Gson gson = new GsonBuilder().setPrettyPrinting().registerTypeAdapter(Location.class, new LocationAdapter()).create();
    try (FileReader reader = new FileReader(f)) {
        GenericNPC[] vils = gson.fromJson(reader, GenericNPC[].class);
        for (GenericNPC gv : vils) {
            if (gv == null)
                continue;
            NPCManager.register(gv);
            genericVillagers.add(gv);
        }
        count += vils.length;
    } catch (JsonSyntaxException | JsonIOException | IOException e) {
        System.err.println("Error reading NPC in " + f.getName() + ".");
        e.printStackTrace();
    }
    return count;
}
 
开发者ID:edasaki,项目名称:ZentrelaRPG,代码行数:19,代码来源:GenericNPCManager.java

示例7: getUsers

import com.google.gson.JsonSyntaxException; //导入依赖的package包/类
/**
 * Получение описания всех юзеров для выбора себя.
 *
 * @param netProperty параметры соединения с сервером
 * @return XML-ответ все юзеры системы
 */
public static LinkedList<QUser> getUsers(INetProperty netProperty) {
    QLog.l().logger().info("Получение описания всех юзеров для выбора себя.");
    // загрузим ответ
    String res = null;
    try {
        res = send(netProperty, Uses.TASK_GET_USERS, null);
    } catch (QException e) {// вывод исключений
        Uses.closeSplash();
        throw new ClientException(Locales.locMes("command_error2"), e);
    } finally {
        if (res == null || res.isEmpty()) {
            System.exit(1);
        }
    }
    final Gson gson = GsonPool.getInstance().borrowGson();
    final RpcGetUsersList rpc;
    try {
        rpc = gson.fromJson(res, RpcGetUsersList.class);
    } catch (JsonSyntaxException ex) {
        throw new ClientException(Locales.locMes("bad_response") + "\n" + ex.toString());
    } finally {
        GsonPool.getInstance().returnGson(gson);
    }
    return rpc.getResult();
}
 
开发者ID:bcgov,项目名称:sbc-qsystem,代码行数:32,代码来源:NetCommander.java

示例8: read

import com.google.gson.JsonSyntaxException; //导入依赖的package包/类
public T read(JsonReader in) throws IOException {
    if (in.peek() == JsonToken.NULL) {
        in.nextNull();
        return null;
    }
    T instance = this.constructor.construct();
    try {
        in.beginObject();
        while (in.hasNext()) {
            BoundField field = (BoundField) this.boundFields.get(in.nextName());
            if (field == null || !field.deserialized) {
                in.skipValue();
            } else {
                field.read(in, instance);
            }
        }
        in.endObject();
        return instance;
    } catch (Throwable e) {
        throw new JsonSyntaxException(e);
    } catch (IllegalAccessException e2) {
        throw new AssertionError(e2);
    }
}
 
开发者ID:JackChan1999,项目名称:letv,代码行数:25,代码来源:ReflectiveTypeAdapterFactory.java

示例9: listBundle

import com.google.gson.JsonSyntaxException; //导入依赖的package包/类
/**
 * 解析ResultListBundle
 *
 * @param json 服务器返回的json数据
 * @param <T>
 * @return
 */
public <T> ResultListBundle<T> listBundle(String json, Class<T> classOfT) {
    ResultListBundle<T> resultBundle = null;
    try {
        Type objectType = new ParameterizedType() {
            public Type getRawType() {
                return ResultListBundle.class;
            }

            public Type[] getActualTypeArguments() {
                return new Type[]{classOfT};
            }

            public Type getOwnerType() {
                return null;
            }
        };
        resultBundle = gson.fromJson(json, objectType);
    } catch (JsonSyntaxException e) {
        LOG.error("无法解析的返回值信息:" + json);
        e.printStackTrace();
    }
    validate(resultBundle);
    return resultBundle;
}
 
开发者ID:bruceq,项目名称:Gather-Platform,代码行数:32,代码来源:ResultBundleResolver.java

示例10: checkJsonStatusResponse

import com.google.gson.JsonSyntaxException; //导入依赖的package包/类
private static void checkJsonStatusResponse(Response response, BaseCallback callback) throws IOException {
    String jsonStr = response.body().string();
    Log.d(TAG, "checkJsonStatusResponse: " + jsonStr);

    mHandler.post(() -> {
        Status status = null;
        try {
            status = new Gson().fromJson(jsonStr, Status.class);
            if (status.getResult()) {
                callback.onSuccess();
            } else {
                callback.onFailure(status.getMessage());
            }
        } catch (JsonSyntaxException e) {
            e.printStackTrace();
            callback.onFailure(RETURN_DATA_ERROR);
        }
    });
}
 
开发者ID:SailFlorve,项目名称:RunHDU,代码行数:20,代码来源:BaseModel.java

示例11: processResponse

import com.google.gson.JsonSyntaxException; //导入依赖的package包/类
private <T> T processResponse(Class<T> responseClass, String body)
        throws APIError {

    Gson gson = new GsonBuilder().setDateFormat("yyyy-MM-dd").create();

    if (body.contains("\"error\":")) {
        ErrorResponse errorResponse = gson.fromJson(body,
                ErrorResponse.class);
        ErrorData error = errorResponse.error;
        throw new APIError(error.message, error.code);
    }

    try {
        return gson.fromJson(body, responseClass);
    } catch (JsonSyntaxException e) {
        throw new APIError("Server error. Invalid response format.", 9999);
    }
}
 
开发者ID:gidim,项目名称:Babler,代码行数:19,代码来源:Client.java

示例12: standAndCheckAdvance

import com.google.gson.JsonSyntaxException; //导入依赖的package包/类
/**
 * Предварительная запись в очередь.
 *
 * @param netProperty netProperty параметры соединения с сервером.
 * @param advanceID идентификатор предварительно записанного.
 * @return XML-ответ.
 */
public static RpcStandInService standAndCheckAdvance(INetProperty netProperty, Long advanceID) {
    QLog.l().logger().info("Постановка предварительно записанных в очередь.");
    // загрузим ответ
    final CmdParams params = new CmdParams();
    params.customerId = advanceID;
    final String res;
    try {
        res = send(netProperty, Uses.TASK_ADVANCE_CHECK_AND_STAND, params);
    } catch (QException e) {// вывод исключений
        throw new ClientException(Locales.locMes("command_error2"), e);
    }
    final Gson gson = GsonPool.getInstance().borrowGson();
    final RpcStandInService rpc;
    try {
        rpc = gson.fromJson(res, RpcStandInService.class);
    } catch (JsonSyntaxException ex) {
        throw new ClientException(Locales.locMes("bad_response") + "\n" + ex.toString());
    } finally {
        GsonPool.getInstance().returnGson(gson);
    }
    return rpc;
}
 
开发者ID:bcgov,项目名称:sbc-qsystem,代码行数:30,代码来源:NetCommander.java

示例13: deserializeResponseBody

import com.google.gson.JsonSyntaxException; //导入依赖的package包/类
private <T> T deserializeResponseBody(Response response, Class<? extends T> bodyType) throws IOException {
    try {
        if (!response.isSuccessful()) {
            throw new APIHttpException(response.code(), response.message());
        }

        JsonReader reader = new JsonReader(new BufferedReader(new InputStreamReader(response.body().byteStream())));
        try {
            return gson.fromJson(reader, bodyType);
        } catch (JsonSyntaxException e) {
            throw new IOException("Malformed JSON response.", e);
        } finally {
            closeQuietly(reader);
        }
    } finally {
        closeQuietly(response);
    }
}
 
开发者ID:pCloud,项目名称:pcloud-sdk-java,代码行数:19,代码来源:RealApiClient.java

示例14: deleteServiseFire

import com.google.gson.JsonSyntaxException; //导入依赖的package包/类
/**
 * Удалить сервис из списока обслуживаемых юзером использую параметры. Используется при
 * добавлении на горячую.
 *
 * @param netProperty параметры соединения с пунктом регистрации
 * @return содержить строковое сообщение о результате.
 */
public static String deleteServiseFire(INetProperty netProperty, long serviceId, long userId) {
    QLog.l().logger().info("Удаление услуги пользователю на горячую.");
    // загрузим ответ
    final CmdParams params = new CmdParams();
    params.userId = userId;
    params.serviceId = serviceId;
    final String res;
    try {
        res = send(netProperty, Uses.TASK_DELETE_SERVICE_FIRE, params);
    } catch (QException e) {
        throw new ClientException(Locales.locMes("bad_response") + "\n" + e.toString());
    }
    final Gson gson = GsonPool.getInstance().borrowGson();
    final RpcGetSrt rpc;
    try {
        rpc = gson.fromJson(res, RpcGetSrt.class);
    } catch (JsonSyntaxException ex) {
        throw new ClientException(Locales.locMes("bad_response") + "\n" + ex.toString());
    } finally {
        GsonPool.getInstance().returnGson(gson);
    }
    return rpc.getResult();
}
 
开发者ID:bcgov,项目名称:sbc-qsystem,代码行数:31,代码来源:NetCommander.java

示例15: mapChartData

import com.google.gson.JsonSyntaxException; //导入依赖的package包/类
public List<PoloniexChartData> mapChartData(String chartDataResult) {

        if (INVALID_CHART_DATA_DATE_RANGE_RESULT.equals(chartDataResult) || INVALID_CHART_DATA_CURRENCY_PAIR_RESULT.equals(chartDataResult)) {
            return Collections.EMPTY_LIST;
        }

        List<PoloniexChartData> results;
        try {
            PoloniexChartData[] chartDataResults = gson.fromJson(chartDataResult, PoloniexChartData[].class);
            results = Arrays.asList(chartDataResults);
        } catch (JsonSyntaxException | DateTimeParseException ex) {
            LogManager.getLogger().error("Exception mapping chart data {} - {}", chartDataResult, ex.getMessage());
            results = Collections.EMPTY_LIST;
        }
        return results;

    }
 
开发者ID:TheCookieLab,项目名称:poloniex-api-java,代码行数:18,代码来源:PoloniexDataMapper.java


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