Example #1
0
  @Test
  public void testGeneralJsonArray() {
    String json = "[333,444,{\"key\" : \"hello\"},666]";
    JsonArray array = Json.toJsonArray(json);

    Assert.assertThat(array.getInteger(0), is(333));
    Assert.assertThat(array.getInteger(1), is(444));
    Assert.assertThat(array.getJsonObject(2).getString("key"), is("hello"));
    Assert.assertThat(array.getInteger(3), is(666));
  }
Example #2
0
  @Test
  public void testMixedGeneralJsonArrayAndJsonObject() {
    String json =
        "[333,444,{\"key\" : \"hello\", \"keyObject\" : [\"object0\",\"object1\"  ]},666]";
    JsonArray array = Json.toJsonArray(json);

    Assert.assertThat(array.getJsonObject(2).getJsonArray("keyObject").getString(0), is("object0"));
    Assert.assertThat(array.getJsonObject(2).getJsonArray("keyObject").getString(1), is("object1"));

    json =
        "{\"key1\":333, \"arrayKey\":[444, \"array\"], \"key2\" :  {\"key3\" : \"hello\", \"key4\":\"world\" }, \"booleanKey\" : true }   ";
    JsonObject jsonObject = Json.toJsonObject(json);
    Assert.assertThat(jsonObject.getJsonArray("arrayKey").getString(1), is("array"));
    Assert.assertThat(jsonObject.getJsonObject("key2").getString("key4"), is("world"));
  }