本文整理汇总了Java中javax.json.JsonArray.get方法的典型用法代码示例。如果您正苦于以下问题:Java JsonArray.get方法的具体用法?Java JsonArray.get怎么用?Java JsonArray.get使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.json.JsonArray
的用法示例。
在下文中一共展示了JsonArray.get方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: toList
import javax.json.JsonArray; //导入方法依赖的package包/类
public static List<Object> toList(JsonArray array) throws JsonException
{
List<Object> list = new ArrayList<Object>();
for (int i = 0; i < array.size(); i++)
{
Object value = array.get(i);
if (value instanceof JsonArray)
{
value = toList((JsonArray) value);
}
else if (value instanceof JsonObject)
{
value = toMap((JsonObject) value);
}
list.add(value);
}
return list;
}
示例2: testWriteTo
import javax.json.JsonArray; //导入方法依赖的package包/类
/**
* check dates
* @throws IOException
*/
@Test
public void testWriteTo() throws IOException {
DecisionDaoProvider provider = new DecisionDaoProvider();
InputStream in = new ByteArrayInputStream(MockData.MockExtraFieldsOne.getBytes(StandardCharsets.UTF_8));
DecisionDao d = DecisionDaoProvider.readFrom(in);
assertEquals(1,d.getSignerIds().size());
final ByteArrayOutputStream buffer = new ByteArrayOutputStream();
OutputStream out = new OutputStream() {
@Override
public void write(int b) throws IOException {
buffer.write(b);
}
};
DecisionDaoProvider.writeTo(d,out);
byte[] arr = buffer.toByteArray();
JsonReader jsonReader = Json.createReader(new StringReader(new String(arr,"utf-8")));
JsonObject ob = jsonReader.readObject();
assertNotNull(ob);
assertEquals("ΑΠΟΦΑΣΗ ΑΝΑΛΗΨΗΣ ΥΠΟΧΡΕΩΣΗΣ",ob.getString("subject"));
assertEquals("Β/100",ob.getString("protocolNumber"));
assertEquals("30",ob.getString("organizationId"));
assertEquals(1,ob.getJsonArray("signerIds").size());
JsonArray signers = ob.getJsonArray("signerIds");
String signerId = (String) signers.getString(0);
assertEquals("10351",signerId);
assertEquals(1,ob.getJsonArray("unitIds").size());
JsonArray units = ob.getJsonArray("unitIds");
String unitId = (String) units.getString(0);
assertEquals("10480",unitId);
JsonObject extra = ob.getJsonObject("extraFieldValues");
assertNotNull(extra);
assertEquals("Τακτικός Προϋπολογισμός",extra.getString("budgettype"));
assertEquals(2014,extra.getInt("financialYear"));
JsonObject amountWithVat = extra.getJsonObject("amountWithVAT");
assertEquals(500,amountWithVat.getInt("amount"));
assertEquals("EUR",amountWithVat.getString("currency"));
JsonArray amountWithKae = extra.getJsonArray("amountWithKae");
assertEquals(2,amountWithKae.size());
JsonObject kae1 = (JsonObject) amountWithKae.get(0);
assertEquals("1234",kae1.getString("kae"));
assertEquals(200.231,kae1.getJsonNumber("amountWithVAT").doubleValue(),0.001);
JsonObject kae2 = (JsonObject) amountWithKae.get(1);
assertEquals("4321",kae2.getString("kae"));
assertEquals(300,kae2.getInt("amountWithVAT"));
}
示例3: parseAddress
import javax.json.JsonArray; //导入方法依赖的package包/类
@Override
public Address parseAddress(JsonObject json) {
JsonArray results = json.getJsonArray("results");
if (!results.isEmpty()) {
Address address = new Address();
JsonObject result = (JsonObject) results.get(0);
JsonArray components = result.getJsonArray("address_components");
for (JsonObject component : components.getValuesAs(JsonObject.class)) {
String value = component.getString("short_name");
typesLoop: for (JsonString type : component.getJsonArray("types").getValuesAs(JsonString.class)) {
switch (type.getString()) {
case "street_number":
address.setHouse(value);
break typesLoop;
case "route":
address.setStreet(value);
break typesLoop;
case "locality":
address.setSettlement(value);
break typesLoop;
case "administrative_area_level_2":
address.setDistrict(value);
break typesLoop;
case "administrative_area_level_1":
address.setState(value);
break typesLoop;
case "country":
address.setCountry(value);
break typesLoop;
case "postal_code":
address.setPostcode(value);
break typesLoop;
default:
break;
}
}
}
return address;
}
return null;
}
示例4: testSuccessResponsePayload
import javax.json.JsonArray; //导入方法依赖的package包/类
/**
* Verifies the health integration with CDI at the scope of a server runtime
*/
@Test
@RunAsClient
public void testSuccessResponsePayload() throws Exception {
Response response = getUrlContents();
// status code
Assert.assertEquals(response.getStatus(), 200);
JsonReader jsonReader = Json.createReader(new StringReader(response.getBody().get()));
JsonObject json = jsonReader.readObject();
System.out.println(json);
// response size
JsonArray checks = json.getJsonArray("checks");
Assert.assertEquals(checks.size(), 1, "Expected a single check response");
// single procedure response
JsonValue check = checks.get(0);
Assert.assertEquals(
asJsonObject(check).getString("name"),
"attributes-check",
"Expected a CDI health check to be invoked, but it was not present in the response"
);
Assert.assertEquals(
asJsonObject(check).getString("state"),
"UP",
"Expected a successful check result"
);
// response payload attributes
JsonObject data = asJsonObject(check).getJsonObject("data");
Assert.assertEquals(
data.getString("first-key"),
"first-val"
);
Assert.assertEquals(
data.getString("second-key"),
"second-val"
);
// overall outcome
Assert.assertEquals(
json.getString("outcome"),
"UP",
"Expected overall outcome to be successful"
);
}