本文整理汇总了Java中org.json.simple.JSONArray.toArray方法的典型用法代码示例。如果您正苦于以下问题:Java JSONArray.toArray方法的具体用法?Java JSONArray.toArray怎么用?Java JSONArray.toArray使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.json.simple.JSONArray
的用法示例。
在下文中一共展示了JSONArray.toArray方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: Logs
import org.json.simple.JSONArray; //导入方法依赖的package包/类
public Logs(JSONArray jLogs) {
for (Object jLog1 : jLogs) {
JSONObject jLog = (JSONObject) jLog1;
byte[] address = Hex.decode((String) jLog.get("address"));
byte[] data = Hex.decode(((String) jLog.get("data")).substring(2));
List<DataWord> topics = new ArrayList<>();
JSONArray jTopics = (JSONArray) jLog.get("topics");
for (Object t : jTopics.toArray()) {
byte[] topic = Hex.decode(((String) t));
topics.add(new DataWord(topic));
}
LogInfo li = new LogInfo(address, topics, data);
logs.add(li);
}
}
示例2: init
import org.json.simple.JSONArray; //导入方法依赖的package包/类
private void init(JSONArray jLogs) {
logs = new ArrayList<>();
for (Object jLog1 : jLogs) {
JSONObject jLog = (JSONObject) jLog1;
byte[] address = Hex.decode((String) jLog.get("address"));
byte[] data = Hex.decode(((String) jLog.get("data")).substring(2));
List<DataWord> topics = new ArrayList<>();
JSONArray jTopics = (JSONArray) jLog.get("topics");
for (Object t : jTopics.toArray()) {
byte[] topic = Hex.decode(((String) t));
topics.add(new DataWord(topic));
}
LogInfo li = new LogInfo(address, topics, data);
logs.add(li);
}
}
示例3: skipNullResults
import org.json.simple.JSONArray; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
private JSONArray skipNullResults(JSONArray source, String propertyName) {
JSONArray result = new JSONArray();
for (Object item : source.toArray()) {
if (((JSONObject) item).get(propertyName) == null) {
continue;
}
result.add(item);
}
return result;
}
示例4: compareJSONArray
import org.json.simple.JSONArray; //导入方法依赖的package包/类
private static Result compareJSONArray(Result result, Object key, JSONArray source, JSONArray toBeCompared) {
if (source == toBeCompared) {
// nullチェック
return result;
}
if (null == toBeCompared) {
result.put(key,
toBeCompared,
String.format("Size of JSONArray [%s] is different. expected[%d], target[null]", key,
source.size()));
}
Object[] expectedArray = source.toArray();
Object[] targetArray = toBeCompared.toArray();
Arrays.sort(expectedArray);
Arrays.sort(targetArray);
if (expectedArray.length != targetArray.length) {
result.put(key,
toBeCompared,
String.format("Size of JSONArray [%s] is different. expected[%d], target[%d]", key,
source.size(),
toBeCompared.size()));
return result;
}
for (int i = 0; i < expectedArray.length; i++) {
Object expected2 = expectedArray[i];
Object target2 = targetArray[i];
if (expected2 instanceof JSONObject && target2 instanceof JSONObject) {
compareJSON(result, key, (JSONObject) expected2, (JSONObject) target2);
} else if (!expected2.equals(target2)) {
result.put(key,
toBeCompared,
String.format("Value of target of key[%s] does "
+ "not have the same value as source JSON. orignal: [%s], target[%s]",
key, source, toBeCompared));
}
}
return result;
}