本文整理匯總了Java中net.minidev.json.JSONArray類的典型用法代碼示例。如果您正苦於以下問題:Java JSONArray類的具體用法?Java JSONArray怎麽用?Java JSONArray使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
JSONArray類屬於net.minidev.json包,在下文中一共展示了JSONArray類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: testEncoding2
import net.minidev.json.JSONArray; //導入依賴的package包/類
@Test
public void testEncoding2() throws ComponentInitializationException, AttributeEncodingException {
init();
IdPAttribute attribute = new IdPAttribute("test");
List<ByteAttributeValue> byteAttributeValues = new ArrayList<ByteAttributeValue>();
byte[] bytes = new byte[2];
bytes[0] = 0;
bytes[1] = 1;
byteAttributeValues.add(new ByteAttributeValue(bytes));
attribute.setValues(byteAttributeValues);
encoder.setAsInt(true);
JSONObject object = encoder.encode(attribute);
JSONArray array = (JSONArray)object.get("attributeName");
JSONArray arrayInts = (JSONArray)array.get(0);
Assert.assertEquals(arrayInts.get(0),0);
Assert.assertEquals(arrayInts.get(1),1);
}
示例2: toString
import net.minidev.json.JSONArray; //導入依賴的package包/類
@SuppressWarnings({ "rawtypes", "unchecked" })
@Override
public String toString(Object value, Object meta, boolean pretty, boolean insertMeta) {
return toString(value, meta, insertMeta, (input) -> {
String json;
if (input instanceof Map) {
json = JSONObject.toJSONString((Map) input);
} else if (input instanceof List) {
json = JSONArray.toJSONString((List) input);
} else if (input instanceof JSONAware) {
json = ((JSONAware) input).toJSONString();
} else if (input instanceof Set) {
json = JSONArray.toJSONString(new ArrayList((Set) input));
} else if (input.getClass().isArray()) {
json = JSONArray.toJSONString(Arrays.asList(input));
} else {
throw new IllegalArgumentException("Unsupported data type (" + input + ")!");
}
if (pretty) {
return JsonBuiltin.format(json);
}
return json;
});
}
示例3: testMarcSchemaIteration
import net.minidev.json.JSONArray; //導入依賴的package包/類
@Test
public void testMarcSchemaIteration() {
List<String> skippable = Arrays.asList("leader", "001", "003", "005", "006", "007", "008");
// fixedValues
for (JsonBranch branch : schema.getPaths()) {
if (skippable.contains(branch.getLabel()) || branch.getParent() != null)
continue;
// List<Map<String, List<String>>> expectedList = fixedValues.get(branch.getLabel());
JSONArray fieldInstances = (JSONArray) cache.getFragment(branch.getJsonPath());
for (int fieldInsanceNr = 0; fieldInsanceNr < fieldInstances.size(); fieldInsanceNr++) {
Map fieldInstance = (Map)fieldInstances.get(fieldInsanceNr);
DataField field = MapToDatafield.parse(fieldInstance, MarcVersion.DNB);
if (!fieldInstance.get("tag").equals("935")) {
assertNotNull(fieldInstance.get("tag").toString() + " should not be null", field);
assertEquals(fieldInstance.get("tag"), field.getTag());
}
}
}
}
示例4: parseJson
import net.minidev.json.JSONArray; //導入依賴的package包/類
@SuppressWarnings({"unchecked", "rawtypes"})
private List<Object> parseJson(JSONRPC2Response response,
Class<?> clazz,
Boolean isArray) {
Gson gson = new Gson();
List objectList = new ArrayList();
if (isArray) {
JSONObject jsonObject = response.toJSONObject();
JSONArray jsonArray = (JSONArray) jsonObject.get("result");
for (int i = 0; i < jsonArray.size(); i++) {
JSONObject item = (JSONObject) jsonArray.get(i);
objectList.add(gson.fromJson(item.toJSONString(), clazz));
}
} else {
Object modelObject = gson.fromJson(response.getResult()
.toString(), clazz);
objectList.add(modelObject);
}
return objectList;
}
示例5: createALotOfInstancesWithDifferentUpdateDate
import net.minidev.json.JSONArray; //導入依賴的package包/類
@BeforeClass
public void createALotOfInstancesWithDifferentUpdateDate() throws Exception {
GraphQLResult result = executeSchemaQuery(addSchema);
assertTrue(result.isSuccessful());
for (int i = 0; i < INSTANCE_COUNT; i++) {
result = instanceService.executeQuery(
addInstance, buildVariableMap(ORDERED_TYPE_NAME), buildSchemaWriteAccess(), DEFAULT_MAX_RECURSE_DEPTH);
assertTrue(result.isSuccessful());
/* Sleep 1 millisecond, just to have a slight spread of 'updateDate'. */
TimeUnit.MILLISECONDS.sleep(1);
}
/* Prerequisites for ordering tests: 'updateDate' has unique values and is of type Long. */
result = instanceService.executeQuery(
findInstances, buildVariableMap(ORDERED_TYPE_NAME), buildSchemaWriteAccess(), DEFAULT_MAX_RECURSE_DEPTH);
assertTrue(result.isSuccessful(), result.getErrors().toString());
String json = objectMapper.writeValueAsString(result.getData());
Object[] dates = JsonPath.<JSONArray>read(json, "$.viewer.instances.edges[*].node.updateDate").toArray();
assertTrue(dates[0] instanceof Long, "Expected updateDate-s to be instances of Long");
assertEquals(new HashSet<>(asList(dates)).size(), INSTANCE_COUNT, "All updateDate-s should have been different.");
}
示例6: checkPageOfSchemas
import net.minidev.json.JSONArray; //導入依賴的package包/類
private void checkPageOfSchemas(
// query params
List<String> argSchemaNames, Object argAfter, Integer argFirst, Object argBefore, Object argLast,
// assertion params
int fetchedCount, boolean hasNext, boolean hasPrevious, int totalCount
) throws Exception {
Map<String, Object> vars = buildSchemaVariableMap();
vars.put("after", argAfter);
vars.put("first", argFirst);
vars.put("before", argBefore);
vars.put("last", argLast);
vars.put("names", argSchemaNames);
GraphQLResult result = schemaService.executeQuery(findSchemas, vars, null);
assertTrue(result.isSuccessful());
String json = objectMapper.writeValueAsString(result.getData());
assertEquals(JsonPath.<JSONArray>read(json, "$.viewer.schemas.edges[*]").toArray().length,
fetchedCount);
assertEquals(JsonPath.read(json, "$.viewer.schemas.totalCount"), (Integer) totalCount);
assertEquals(JsonPath.read(json, "$.viewer.schemas.pageInfo.hasNextPage"), (Boolean) hasNext);
assertEquals(JsonPath.read(json, "$.viewer.schemas.pageInfo.hasPreviousPage"), (Boolean) hasPrevious);
}
示例7: checkPageOfInstances
import net.minidev.json.JSONArray; //導入依賴的package包/類
private void checkPageOfInstances(
// query params
List<String> argInstanceIds, Object argAfter, Integer argFirst, Object argBefore, Object argLast,
// assertion params
int fetchedCount, boolean hasNext, boolean hasPrevious, int totalCount
) throws Exception {
Map<String, Object> vars = buildVariableMap("paged0");
vars.put("after", argAfter);
vars.put("first", argFirst);
vars.put("before", argBefore);
vars.put("last", argLast);
vars.put("ids", argInstanceIds);
GraphQLResult result =
instanceService.executeQuery(findInstances, vars, buildSchemaWriteAccess(), DEFAULT_MAX_RECURSE_DEPTH);
assertTrue(result.isSuccessful());
String json = objectMapper.writeValueAsString(result.getData());
assertEquals(JsonPath.<JSONArray>read(json, "$.viewer.instances.edges[*]").toArray().length,
fetchedCount);
assertEquals(JsonPath.read(json, "$.viewer.instances.totalCount"), (Integer) totalCount);
assertEquals(JsonPath.read(json, "$.viewer.instances.pageInfo.hasNextPage"), (Boolean) hasNext);
assertEquals(JsonPath.read(json, "$.viewer.instances.pageInfo.hasPreviousPage"),
(Boolean) hasPrevious);
}
示例8: testbrokenLink
import net.minidev.json.JSONArray; //導入依賴的package包/類
@Test
public void testbrokenLink() throws IOException, URISyntaxException {
JSONObject object = new JSONObject();
object.put("key", "sprSCKKWf8xUeXxEo6Bv0lE1sSjWRDkO");
object.put("marketName", "eoemarket");
object.put("count", 1);
JSONArray data = new JSONArray();
JSONObject o = new JSONObject();
o.put("id", -1);
o.put("link", "http://testsssssss");
o.put("statusCode", 404);
data.add(o);
object.put("data", data);
String test = "eyJjb3VudCI6IDEwLCAibWFya2V0TmFtZSI6ICJBcHBDaGluYSIsICJkYXRhIjogW3sibGluayI6ICJodHRwOi8vd3d3LmFwcGNoaW5hLmNvbS9hcHAvY29tLmdvb2dsZS5hbmRyb2lkLmFwcHMubWFwcyIsICJpZCI6IDEsICJzdGF0dXNDb2RlIjogNDA0fSwgeyJsaW5rIjogImh0dHA6Ly93d3cuYXBwY2hpbmEuY29tL2FwcC9jb20ud2VhdGhlci5XZWF0aGVyIiwgImlkIjogMiwgInN0YXR1c0NvZGUiOiA0MDR9LCB7ImxpbmsiOiAiaHR0cDovL3d3dy5hcHBjaGluYS5jb20vYXBwL2NvbS5zdHlsZW0ud2FsbHBhcGVycyIsICJpZCI6IDQsICJzdGF0dXNDb2RlIjogNDA0fSwgeyJsaW5rIjogImh0dHA6Ly93d3cuYXBwY2hpbmEuY29tL2FwcC9jb20uc2hhemFtLmVuY29yZS5hbmRyb2lkIiwgImlkIjogNSwgInN0YXR1c0NvZGUiOiA0MDR9LCB7ImxpbmsiOiAiaHR0cDovL3d3dy5hcHBjaGluYS5jb20vYXBwL2NvbS5yaW5nZHJvaWQiLCAiaWQiOiA2LCAic3RhdHVzQ29kZSI6IDQwNH0sIHsibGluayI6ICJodHRwOi8vd3d3LmFwcGNoaW5hLmNvbS9hcHAvY29tLnAxLmNob21wc21zIiwgImlkIjogNywgInN0YXR1c0NvZGUiOiA0MDR9LCB7ImxpbmsiOiAiaHR0cDovL3d3dy5hcHBjaGluYS5jb20vYXBwL2NvbS5oYW5kY2VudC5uZXh0c21zIiwgImlkIjogOCwgInN0YXR1c0NvZGUiOiA0MDR9LCB7ImxpbmsiOiAiaHR0cDovL3d3dy5hcHBjaGluYS5jb20vYXBwL2NvbS5mYWNlYm9vay5rYXRhbmEiLCAiaWQiOiA5LCAic3RhdHVzQ29kZSI6IDQwNH0sIHsibGluayI6ICJodHRwOi8vd3d3LmFwcGNoaW5hLmNvbS9hcHAvY29tLmNvZGUuaS5tdXNpYyIsICJpZCI6IDEwLCAic3RhdHVzQ29kZSI6IDQwNH0sIHsibGluayI6ICJodHRwOi8vd3d3LmFwcGNoaW5hLmNvbS9hcHAvY29tLmJpZ2d1LnNob3BzYXZ2eSIsICJpZCI6IDExLCAic3RhdHVzQ29kZSI6IDQwNH1dLCAia2V5IjogImpqRzhMa0MzTUh5RjlYY3NWS2g2Rkh4bXRMQ05ZdE14In0=";
Reader input = new StringReader(object.toJSONString());
byte[] binaryData = IOUtils.toByteArray(input, "UTF-8");
String encodeBase64 = Base64.encodeBase64String(binaryData);
System.out.println(encodeBase64);
String url = "http://localhost:9080/sjk-market-admin/market/brokenLink.d";
url = "http://app.sjk.ijinshan.com/market/brokenLink.d";
URIBuilder builder = new URIBuilder(url);
builder.setParameter("c", test);
DefaultHttpClient httpclient = new DefaultHttpClient();
HttpPost httpPost = new HttpPost(builder.build());
HttpResponse response = httpclient.execute(httpPost);
logger.debug("URI: {} , {}", url, response.getStatusLine());
HttpEntity entity = response.getEntity();
InputStream is = entity.getContent();
// be convinient to debug
String rspJSON = IOUtils.toString(is, "UTF-8");
System.out.println(rspJSON);
}
示例9: testbrokenLink
import net.minidev.json.JSONArray; //導入依賴的package包/類
@Test
public void testbrokenLink() throws IOException, URISyntaxException {
JSONObject object = new JSONObject();
object.put("key", "sprSCKKWf8xUeXxEo6Bv0lE1sSjWRDkO");
object.put("marketName", "eoemarket");
object.put("count", 1);
JSONArray data = new JSONArray();
JSONObject o = new JSONObject();
o.put("id", -1);
o.put("link", "http://testsssssss");
o.put("statusCode", 404);
data.add(o);
object.put("data", data);
Reader input = new StringReader(object.toJSONString());
byte[] binaryData = IOUtils.toByteArray(input, "UTF-8");
String encodeBase64 = Base64.encodeBase64String(binaryData);
String url = "http://localhost:8080/sjk-market/market/brokenLink.d";
url = "http://app-t.sjk.ijinshan.com/market/brokenLink.d";
URIBuilder builder = new URIBuilder(url);
builder.setParameter("c", encodeBase64);
DefaultHttpClient httpclient = new DefaultHttpClient();
HttpPost httpPost = new HttpPost(builder.build());
HttpResponse response = httpclient.execute(httpPost);
logger.debug("URI: {} , {}", url, response.getStatusLine());
HttpEntity entity = response.getEntity();
InputStream is = entity.getContent();
// be convinient to debug
String rspJSON = IOUtils.toString(is, "UTF-8");
System.out.println(rspJSON);
}
示例10: asStrings
import net.minidev.json.JSONArray; //導入依賴的package包/類
@Override
public List<String> asStrings(String paramName, Mode mode) throws Exception {
Collection<Object> collection = valuesFor(paramName, mode);
List<String> list = new LinkedList<>();
for (Object obj : collection) {
if (obj instanceof JSONArray) {
JSONArray jsonArray = (JSONArray) obj;
for (int i = 0; i < jsonArray.size(); i++) {
Object objFinal = jsonArray.get(i);
if (objFinal instanceof String) {
String value = (String) objFinal;
list.add(value);
}
}
}
}
return list;
}
示例11: checkPrincipal
import net.minidev.json.JSONArray; //導入依賴的package包/類
public boolean checkPrincipal(Object identity) {
if (identity != null && identity instanceof OIDCPrincipal) {
super.loginOk = true;
this.identity = (OIDCPrincipal) identity;
Group roles = new SimpleGroup(SecurityConstants.ROLES_IDENTIFIER);
if (identity != null && rolesClaimName != null) {
Object rolesClaim = this.identity.getClaims().get(rolesClaimName);
if (rolesClaim instanceof JSONArray) {
((List<String>) rolesClaim).forEach(r -> roles.addMember(new SimplePrincipal(r)));
}
}
this.roleSets = new Group[] { roles };
return true;
}
return false;
}
示例12: changeset_is_only_created_for_the_changed_fields
import net.minidev.json.JSONArray; //導入依賴的package包/類
@Test
public void changeset_is_only_created_for_the_changed_fields() {
// given
postDocument(document);
postDocument(document.put("name", "NewService").put("owner", "User Team"));
// when
JSONArray changeset = JsonPath.read(getChangesetsOfDocumentWithSomeIdAsString(), "$.[?(@.order == 2)]");
assertThat(changeset).hasSize(1);
Object firstChangeset = changeset.get(0);
JSONArray changedFields = JsonPath.read(firstChangeset, "$.fields");
assertThat(changedFields).hasSize(2);
// then
assertThatFieldHasCorrectDiff(firstChangeset, "/name", "NewService", REPLACE_OPERATION);
assertThatFieldHasCorrectDiff(firstChangeset, "/owner", "User Team", REPLACE_OPERATION);
}
示例13: changesets_per_document_contain_incremented_order_numbers
import net.minidev.json.JSONArray; //導入依賴的package包/類
@Test
public void changesets_per_document_contain_incremented_order_numbers() {
// given
postDocument(document);
// and
document = document.put("name", "NewService");
postDocument(document);
// and
document = document.put("owner", "User Team");
postDocument(document);
// when
String changesets = getChangesetsOfDocumentWithSomeIdAsString();
// then
assertThat(((JSONArray) JsonPath.read(changesets, "$.[?(@.order == 1)]"))).hasSize(1);
assertThat(((JSONArray) JsonPath.read(changesets, "$.[?(@.order == 2)]"))).hasSize(1);
assertThat(((JSONArray) JsonPath.read(changesets, "$.[?(@.order == 3)]"))).hasSize(1);
assertThat(((JSONArray) JsonPath.read(changesets, "$.[?(@.order == 4)]"))).hasSize(0);
}
示例14: childByIndex
import net.minidev.json.JSONArray; //導入依賴的package包/類
@Override
public ChildByIndex childByIndex(int i) {
return new ChildByIndex(i) {
@Override
public Object applyTo(Object node, Path enclosingPath, int currStepNo) {
// System.out.println("apply " + this + " to " + node);
if (node instanceof JSONArray && inRange((JSONArray) node, i)) {
Object jo = ((JSONArray) node).get(i);
return skipArrays && jo instanceof JSONArray ? skipArray(jo, enclosingPath, currStepNo) : jo;
}
return null;
}
};
}
示例15: downloadLibraries
import net.minidev.json.JSONArray; //導入依賴的package包/類
public static void downloadLibraries(String file) throws MalformedURLException, ParseException, IOException {
File launcherProfiles = new File(file + "download\\install_profile.json");
JSONParser p = new JSONParser();
JSONObject obj = (JSONObject) p.parse(launcherProfiles.toURL().openStream());
JSONObject versionInfo = (JSONObject) obj.get("versionInfo");
JSONArray libraries = (JSONArray) versionInfo.get("libraries");
for (Object lib2 : libraries) {
JSONObject lib = (JSONObject) lib2;
// if (lib.containsKey("clientreq")) {
// Boolean client = (Boolean) lib.get("clientreq");
// if (client) {
String name = (String) lib.get("name");
if (lib.containsKey("url")) {
CLUtil.downloadMaven(name, new File(file + "libraries\\"), (String) lib.get("url"));
} else {
CLUtil.downloadMaven(name, new File(file + "libraries\\"));
}
// }
// }
}
// System.exit(0);
}