类android.util.MalformedJsonException源码实例Demo

下面列出了怎么用android.util.MalformedJsonException的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: 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();
}
 
源代码2 项目: 365browser   文件: JsonSanitizer.java
private static String sanitizeString(String string) throws MalformedJsonException {
    if (!checkString(string)) {
        throw new MalformedJsonException("Invalid escape sequence");
    }
    return string;
}