Beispiel #1
0
 public void testNullAsString() {
   json(swapQuotes("['hello',null,'there']"));
   json.enterList();
   assertStringsMatch("hello", json.nextString());
   assertNull(json.nextString());
   assertStringsMatch("there", json.nextString());
   assertFalse(json.hasNext());
 }
Beispiel #2
0
 public static OurClass parse(JSONParser json) {
   json.enterList();
   String message = json.nextString();
   int number = json.nextInt();
   json.exit();
   return new OurClass(message, number);
 }
Beispiel #3
0
 public void testString() {
   StringBuilder sb = new StringBuilder();
   for (int i = 0; i < 1000; i++) {
     sb.append((char) i);
   }
   String originalString = sb.toString();
   enc().encode(originalString);
   String jsonString = enc.toString();
   json(jsonString);
   String decodedString = json.nextString();
   assertStringsMatch(decodedString, originalString);
 }
Beispiel #4
0
  public void testArray() {
    String orig = "[0,1,2,3,\"hello\"]";

    json(orig);
    json.enterList();
    for (int i = 0; i < 4; i++) {
      assertTrue(json.hasNext());
      assertEquals(i, json.nextInt());
    }
    assertTrue(json.hasNext());
    assertStringsMatch("hello", json.nextString());
    assertFalse(json.hasNext());
    json.exit();
  }