Java 类android.util.MalformedJsonException 实例源码

项目:RxJavaAndRetrofitSimple    文件:ResponseExceptionJobber.java   
public static String analyze(Throwable e) {
    if (!NetConnectionUtils.isNetConnected(BaseApplication.getInstance())) {
        return "当前网络不可用,请检查网络设置";
    } else if (e instanceof UnknownHostException) {
        return "网络错误,请重试";
    } else if (e instanceof ConnectException) {
        return "请求失败,请重试";
    } else if (e instanceof MalformedJsonException) {
        return "请求失败,请重试";
    } else if (e instanceof SocketTimeoutException) {
        return "请求超时,请重试";
    } else {
        return "请求失败,请重试";
    }
}
项目:android-galaxyzoo    文件:ZooniverseClientTest.java   
@Test
public void testLoginWithFailure() throws IOException {
    final MockWebServer server = new MockWebServer();


    //On failure, the server's response code is HTTP_OK,
    //but it has a "success: false" parameter.
    final MockResponse response = new MockResponse();
    response.setResponseCode(HttpURLConnection.HTTP_OK);
    response.setBody("test nonsense failure message");
    server.enqueue(response);
    server.start();

    final ZooniverseClient client = createZooniverseClient(server);


    try {
        final LoginUtils.LoginResult result = client.loginSync("testusername", "testpassword");
        assertNotNull(result);
        assertFalse(result.getSuccess());
    } catch (final ZooniverseClient.LoginException e) {
        assertTrue(e.getCause() instanceof MalformedJsonException);
    }



    server.shutdown();
}
项目:365browser    文件:JsonSanitizer.java   
private static String sanitizeString(String string) throws MalformedJsonException {
    if (!checkString(string)) {
        throw new MalformedJsonException("Invalid escape sequence");
    }
    return string;
}