当前位置: 首页>>代码示例>>Java>>正文


Java JSONArray类代码示例

本文整理汇总了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);
}
 
开发者ID:CSCfi,项目名称:shibboleth-idp-oidc-extension,代码行数:18,代码来源:OIDCByteAttributeEncoderTest.java

示例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;
	});
}
 
开发者ID:berkesa,项目名称:datatree-adapters,代码行数:25,代码来源:JsonSmart.java

示例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());
			}
		}
	}
}
 
开发者ID:pkiraly,项目名称:metadata-qa-marc,代码行数:21,代码来源:MarcIteratorTest.java

示例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;
}
 
开发者ID:CactusSoft,项目名称:zabbkit-android,代码行数:22,代码来源:ZabbKitServerManager.java

示例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.");
}
 
开发者ID:nfl,项目名称:gold,代码行数:23,代码来源:OrderByTest.java

示例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);
}
 
开发者ID:nfl,项目名称:gold,代码行数:24,代码来源:PaginationTest.java

示例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);
}
 
开发者ID:nfl,项目名称:gold,代码行数:26,代码来源:PaginationTest.java

示例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);
}
 
开发者ID:zhaoxi1988,项目名称:sjk,代码行数:37,代码来源:ControllerTest.java

示例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);
}
 
开发者ID:zhaoxi1988,项目名称:sjk,代码行数:35,代码来源:ControllerTest.java

示例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;
}
 
开发者ID:DantaFramework,项目名称:JahiaDF,代码行数:19,代码来源:JahiaConfigurationProviderImpl.java

示例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;
}
 
开发者ID:aaronanderson,项目名称:swarm-oidc,代码行数:19,代码来源:OIDCLoginModule.java

示例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);
}
 
开发者ID:pivio,项目名称:pivio-server,代码行数:19,代码来源:ChangesetApiTest.java

示例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);
}
 
开发者ID:pivio,项目名称:pivio-server,代码行数:23,代码来源:ChangesetApiTest.java

示例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;
			}
		};
	}
 
开发者ID:a-f-m,项目名称:apath,代码行数:19,代码来源:JsonSmartStepBuilder.java

示例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);
}
 
开发者ID:mcNETDev,项目名称:CLauncher,代码行数:24,代码来源:CLUtil.java


注:本文中的net.minidev.json.JSONArray类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。