當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。