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


Java JSONArray.get方法代码示例

本文整理汇总了Java中net.minidev.json.JSONArray.get方法的典型用法代码示例。如果您正苦于以下问题:Java JSONArray.get方法的具体用法?Java JSONArray.get怎么用?Java JSONArray.get使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在net.minidev.json.JSONArray的用法示例。


在下文中一共展示了JSONArray.get方法的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: 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

示例3: 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

示例4: 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

示例5: 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

示例6: extractInnerArray

import net.minidev.json.JSONArray; //导入方法依赖的package包/类
private static List<EdmFieldInstance> extractInnerArray(Object outerVal, String recordId, String jsonPath) {
	List<EdmFieldInstance> extracted = new ArrayList<>();
	JSONArray array = (JSONArray) outerVal;
	for (int j = 0, l2 = array.size(); j < l2; j++) {
		Object innerVal = array.get(j);
		if (innerVal.getClass() == String.class) {
			extracted.add(new EdmFieldInstance((String) innerVal));
		} else if (innerVal.getClass() == LinkedHashMap.class) {
			extracted.add(hashToFieldInstance(innerVal, recordId, jsonPath));
		} else if (innerVal.getClass() == JSONArray.class) {
			extracted.addAll(extractInnerArray(innerVal, recordId, jsonPath));
		} else {
			logger.severe(String.format(
					  "Unhandled inner array type: %s, [record ID: %s, path: %s]",
					  getType(array.get(j)), recordId, jsonPath
			));
		}
	}
	return extracted;
}
 
开发者ID:pkiraly,项目名称:metadata-qa-api,代码行数:21,代码来源:JsonUtils.java

示例7: evaluate

import net.minidev.json.JSONArray; //导入方法依赖的package包/类
/**
 * This method evaluates the jsonpath expression on the supplied
 * node.
 *
 * @param jsonpath The jsonpath expression
 * @param data The json data
 * @return The result, or null if not found (which may be due to an expression error)
 */
public static String evaluate(String jsonpath, Object data) {
    String json = serialize(data);

    // No jsonpath means return serialized form
    if (jsonpath == null || jsonpath.trim().isEmpty()) {
        return json;
    }

    if (json != null) {
        Object result = JsonPath.parse(json).read(jsonpath);
        if (result != null) {
            if (result.getClass() == JSONArray.class) {
                JSONArray arr=(JSONArray)result;
                if (arr.isEmpty()) {
                    result = null;
                } else if (arr.size() == 1) {
                    result = arr.get(0);
                }
            }
            return serialize(result);
        }
    }
    return null;
}
 
开发者ID:hawkular,项目名称:hawkular-apm,代码行数:33,代码来源:JSON.java

示例8: readAtomFeed

import net.minidev.json.JSONArray; //导入方法依赖的package包/类
@Override
public final List<URI> readAtomFeed(final InputStream in) {

    final List<URI> uris = new ArrayList<>();

    final JsonReader jsonReader = Json.createReader(new InputStreamReader(in));
    final JsonObject jsonObj = jsonReader.readObject();
    final JSONArray read = JsonPath.read(jsonObj, "$.entries..id");
    if (read != null) {
        for (int i = 0; i < read.size(); i++) {
            final JsonString id = (JsonString) read.get(i);
            final String uri = id.getString();
            try {
                uris.add(Utils4J.url(uri).toURI());
            } catch (final URISyntaxException ex) {
                throw new RuntimeException("Couldn't create URI: " + uri);
            }
        }
    }

    return uris;

}
 
开发者ID:fuinorg,项目名称:event-store-commons,代码行数:24,代码来源:AtomFeedJsonReader.java

示例9: doCheck

import net.minidev.json.JSONArray; //导入方法依赖的package包/类
private void doCheck() throws IOException {
    URLConnection urlConnection = url.openConnection();
    urlConnection.setConnectTimeout(3000); // curse can be slow, this should be good though
    urlConnection.setDoOutput(true);
    InputStream inputStream = urlConnection.getInputStream();
    JSONArray jsonArray = (JSONArray) JSONValue.parse(inputStream);
    inputStream.close();

    // process the result
    if (jsonArray.size() == 0) {
        BGDCore.getLogging().warning("Failed to update plugin \"" + plugin.getName() + "\" due to invalid id '" + id + "!");
        return;
    }
    JSONObject updateData = (JSONObject) jsonArray.get(jsonArray.size() - 1);
    String remoteVersion = (String) updateData.get("name");
    if (remoteVersion.lastIndexOf("v") < remoteVersion.length() - 7) {
        BGDCore.getLogging().warning("Invalid remote version '" + updateData.get("name") + "' (" + remoteVersion.lastIndexOf("v") + ") for plugin \"" + plugin.getName() + "\"!");
        return;
    }
    String hostVersion = remoteVersion.substring(remoteVersion.lastIndexOf("v") + 1);
    if (hostVersion.equalsIgnoreCase(plugin.getDescription().getVersion())) {
        // same version! no update needed
        return;
    }
    latestFileURL = new URL((String) updateData.get("downloadUrl"));
}
 
开发者ID:BurnGames,项目名称:BGDCore,代码行数:27,代码来源:PluginUpdater.java

示例10: getAllParameters

import net.minidev.json.JSONArray; //导入方法依赖的package包/类
public static Map<String, String[]> getAllParameters(String json) {
    Map<String, String[]> results = new HashMap<String, String[]>();
    JSONArray props = JsonPath.read(json, LEROY_BUILDER_PARAMETERS_JPATH);
    if (props != null) {
        for (int i = 0; i < props.size(); i++) {
            JSONObject property = (JSONObject) props.get(i);
            String choices = (String) property.get("choices");
            if (choices != null) {
                String[] choicesArr = choices.split("\n");
                String name = (String) property.get("name");
                if (name != null && !name.isEmpty()) {
                    results.put(name, choicesArr);
                }
            }
        }
    }
    return results;
}
 
开发者ID:epicforce,项目名称:leroy_jenkins,代码行数:19,代码来源:JsonUtils.java

示例11: getTargets

import net.minidev.json.JSONArray; //导入方法依赖的package包/类
public static List<LeroyBuilder.Target> getTargets(String jsonForm) {

        // find Leroy builder
        List<LeroyBuilder.Target> result = new ArrayList<LeroyBuilder.Target>();

        String leroyBuilderJson = getLeroyBuilderJSON(jsonForm);
        Object targetsObj = (Object) JsonPath.read(leroyBuilderJson, "$.[0].targets");
        if (targetsObj != null) {
            if (targetsObj instanceof JSONObject) {
                result.add(populateTarget((JSONObject) targetsObj));
            } else {
                JSONArray targets = (JSONArray) targetsObj;
                for (int i = 0; i < targets.size(); i++) {
                    JSONObject target = (JSONObject) targets.get(i);
                    if (target != null) {
                        result.add(populateTarget(target));
                    }
                }
            }
        }
        return result;
    }
 
开发者ID:epicforce,项目名称:leroy_jenkins,代码行数:23,代码来源:JsonUtils.java

示例12: getHostIP

import net.minidev.json.JSONArray; //导入方法依赖的package包/类
String getHostIP(JsonElement requestResponse) {
    if (requestResponse == null) {
        return null;
    }

    ReadContext ctx = JsonPath.parse(requestResponse.toString());
    JSONArray o = ctx.read("$.content[*].data.ip_address");

    if (o == null || o.size() < 1 || o.get(0) == null) {
        return null;
    }

    return o.get(0).toString();
}
 
开发者ID:cf-platform-eng,项目名称:vrealize-service-broker,代码行数:15,代码来源:VraClient.java

示例13: getJSONObjectValues

import net.minidev.json.JSONArray; //导入方法依赖的package包/类
private HashMap<String, String> getJSONObjectValues(JSONObject obj){
    HashMap<String, String> result = new HashMap<String, String>();;

    if(obj.containsKey("value")) {

        JSONArray value = (JSONArray)obj.get("value");
        for(int i=0;i<value.size();i++) {
            JSONObject jo = (JSONObject) value.get(i);
            Set<String> keys = jo.keySet();
            for(String key : keys){
                result.put(key, jo.get(key).toString());
            }
        }
    }


    if (obj.containsKey("answerSdp")){
        String sd = (String)obj.get("answerSdp");
        result.put("answerSdp", sd);
    }

    if (obj.containsKey("sinkId")){
        result.put("sinkId", (String)obj.get("sinkId"));
    }

    if (result.isEmpty()) {
        result = null;
    }

    return result;
}
 
开发者ID:nubomedia-vtt,项目名称:kurento-tree-client-android,代码行数:32,代码来源:TreeResponse.java

示例14: extractList

import net.minidev.json.JSONArray; //导入方法依赖的package包/类
public static List<String> extractList(Object value) {
	List<String> extracted = new ArrayList<>();
	if (value.getClass() == String.class) {
		extracted.add((String) value);
	} else if (value.getClass() == JSONArray.class) {
		JSONArray array1 = (JSONArray) value;
		for (int i = 0, l = array1.size(); i < l; i++) {
			if (array1.get(i).getClass() == JSONArray.class) {
				JSONArray array2 = (JSONArray) array1.get(i);
				for (int j = 0, l2 = array2.size(); j < l2; j++) {
					if (array2.get(j).getClass() == String.class) {
						extracted.add((String) array2.get(j));
					} else if (array2.get(j).getClass() == LinkedHashMap.class) {
						Map<String, String> map = (LinkedHashMap<String, String>) array2.get(j);
						if (map.containsKey("@about")) {
							extracted.add(map.get("@about"));
						} else if (map.containsKey("@resource")) {
							extracted.add(map.get("@resource"));
						} else if (map.containsKey("#value")) {
							extracted.add(map.get("#value"));
						} else {
							logger.severe("Other type of map*: " + map.keySet());
						}
					} else {
						logger.severe("Unhandled array2 type: " + getType(array2.get(j)));
					}
				}
			} else {
				logger.severe("Unhandled array1 type: " + getType(array1.get(i)));
			}
		}
	} else {
		logger.severe("Unhandled object type: " + getType(value));
	}
	return extracted;
}
 
开发者ID:pkiraly,项目名称:metadata-qa-api,代码行数:37,代码来源:JsonUtils.java

示例15: testDatafieldDeconstruction

import net.minidev.json.JSONArray; //导入方法依赖的package包/类
@Test
public void testDatafieldDeconstruction() {
	Object rawFragment = cache.getFragment("$.datafield[?(@.tag == '935')]");
	assertEquals(JSONArray.class, rawFragment.getClass());
	assertEquals(
			"[{\"tag\":\"935\",\"ind1\":\" \",\"ind2\":\" \"," +
					"\"subfield\":[{\"code\":\"a\",\"content\":\"mteo\"}]}," +
					"{\"tag\":\"935\",\"ind1\":\" \",\"ind2\":\" \"," +
					"\"subfield\":[{\"code\":\"b\",\"content\":\"druck\"}]}]",
			rawFragment.toString());

	JSONArray fragments = (JSONArray)rawFragment;
	assertEquals(2, fragments.size());
	assertEquals(LinkedHashMap.class, fragments.get(0).getClass());

	Map fragment1 = (Map)fragments.get(0);
	assertEquals("tag, ind1, ind2, subfield", StringUtils.join(fragment1.keySet(), ", "));
	assertEquals(String.class, fragment1.get("tag").getClass());
	assertEquals(String.class, fragment1.get("ind1").getClass());
	assertEquals(String.class, fragment1.get("ind2").getClass());
	assertEquals(JSONArray.class, fragment1.get("subfield").getClass());

	JSONArray subfields = (JSONArray) fragment1.get("subfield");
	assertEquals(1, subfields.size());
	assertEquals(LinkedHashMap.class, subfields.get(0).getClass());

	Map subfield = (Map) subfields.get(0);
	assertEquals("{code=a, content=mteo}", subfield.toString());
	assertEquals(2, subfield.size());
	assertEquals("code, content", StringUtils.join(subfield.keySet(), ", "));
	assertEquals("a", subfield.get("code"));
	assertEquals("mteo", subfield.get("content"));
}
 
开发者ID:pkiraly,项目名称:metadata-qa-api,代码行数:34,代码来源:MarcJsonTest.java


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