本文整理匯總了Java中net.minidev.json.JSONArray.size方法的典型用法代碼示例。如果您正苦於以下問題:Java JSONArray.size方法的具體用法?Java JSONArray.size怎麽用?Java JSONArray.size使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類net.minidev.json.JSONArray
的用法示例。
在下文中一共展示了JSONArray.size方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: 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());
}
}
}
}
示例2: 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;
}
示例3: 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;
}
示例4: 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;
}
示例5: 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;
}
示例6: 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;
}
示例7: listunspent
import net.minidev.json.JSONArray; //導入方法依賴的package包/類
private Object listunspent(long minconf, long maxconf, JSONArray filter) {
List<String> addresses = new ArrayList<String>(filter.size());
for (Object item : filter) addresses.add((String) item);
JSONArray reply = new JSONArray();
// We want to list absolutely everything, so we call
// calculateAllSpendCandidates with false, false.
List<TransactionOutput> unspent = kit.wallet().calculateAllSpendCandidates(false, false);
for (TransactionOutput out : unspent) {
Transaction parent = out.getParentTransaction();
int depth = -1;
if (parent != null) depth = parent.getConfidence().getDepthInBlocks();
String addr = txoutScript2String(params,out);
if (minconf <= depth && depth <= maxconf && (addresses.size() == 0 || addresses.contains(addr))) {
JSONObject coin = new JSONObject();
TransactionOutPoint outpoint = out.getOutPointFor();
coin.put("txid", outpoint.getHash().toString());
coin.put("vout",outpoint.getIndex());
coin.put("address",addr);
coin.put("scriptPubKey", DatatypeConverter.printHexBinary(out.getScriptPubKey().getProgram()));
coin.put("amount", coin2BigDecimal(out.getValue()));
coin.put("confirmations",depth);
reply.add(coin);
}
}
return reply;
}
示例8: 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"));
}
示例9: sort
import net.minidev.json.JSONArray; //導入方法依賴的package包/類
private JSONArray sort(final JsonPathHelper pathHelper, JSONArray a, final String nestedPathExpr) {
List<String> elements = new ArrayList<>(a.size());
for (Object element : a) {
net.minidev.json.JSONObject jsonObject = new net.minidev.json.JSONObject((Map<String, ?>) element);
elements.add(jsonObject.toJSONString());
}
Collections.sort(elements, new Comparator<String>() {
@Override
public int compare(String o1, String o2) {
Comparable val1 = (Comparable) pathHelper.getJsonPath(o1, nestedPathExpr);
Comparable val2 = (Comparable) pathHelper.getJsonPath(o2, nestedPathExpr);
return val1.compareTo(val2);
}
});
return convertToArray(elements);
}
示例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;
}
示例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;
}
示例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();
}
示例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;
}
示例14: mapJsonToCustomers
import net.minidev.json.JSONArray; //導入方法依賴的package包/類
public List<Customer> mapJsonToCustomers(String json) throws ParseException {
List<Customer> customers = new ArrayList<>();
DocumentContext jsonContext = JsonUtil.getJsonContext(json);
JSONArray jsonCustomers = jsonContext.read("$.customers");
for (int i = 0; i < jsonCustomers.size(); i++) {
Number id = jsonContext.read("$.customers[" + i + "].id");
String firstName = jsonContext.read("$.customers[" + i + "].firstName");
String lastName = jsonContext.read("$.customers[" + i + "].lastName");
customers.add(new Customer(id.longValue(), firstName, lastName));
}
return customers;
}
示例15: 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;
}