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


Java JSONArray.add方法代码示例

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


在下文中一共展示了JSONArray.add方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: notify

import org.json.simple.JSONArray; //导入方法依赖的package包/类
@Override
public void notify(Block block) {
    JSONObject response = new JSONObject();
    JSONArray addedRecentBlocks = new JSONArray();
    JSONObject addedRecentBlock = new JSONObject();
    addedRecentBlock.put("index", Users.getIndex(block));
    addedRecentBlock.put("timestamp", block.getTimestamp());
    addedRecentBlock.put("numberOfTransactions", block.getTransactions().size());
    addedRecentBlock.put("totalAmountNQT", block.getTotalAmountNQT());
    addedRecentBlock.put("totalFeeNQT", block.getTotalFeeNQT());
    addedRecentBlock.put("payloadLength", block.getPayloadLength());
    addedRecentBlock.put("generator", Convert.toUnsignedLong(block.getGeneratorId()));
    addedRecentBlock.put("height", block.getHeight());
    addedRecentBlock.put("version", block.getVersion());
    addedRecentBlock.put("block", block.getStringId());
    addedRecentBlock.put("baseTarget", BigInteger.valueOf(block.getBaseTarget()).multiply(BigInteger.valueOf(100000)).divide(BigInteger.valueOf(Constants.INITIAL_BASE_TARGET)));
    addedRecentBlocks.add(addedRecentBlock);
    response.put("addedRecentBlocks", addedRecentBlocks);
    Users.sendNewDataToAll(response);
}
 
开发者ID:muhatzg,项目名称:burstcoin,代码行数:21,代码来源:Users.java

示例2: getPluginData

import org.json.simple.JSONArray; //导入方法依赖的package包/类
/**
 * Gets the plugin specific data.
 * This method is called using Reflection.
 *
 * @return The plugin specific data.
 */
public JSONObject getPluginData() {
    JSONObject data = new JSONObject();

    String pluginName = plugin.getDescription().getName();
    String pluginVersion = plugin.getDescription().getVersion();

    data.put("pluginName", pluginName); // Append the name of the plugin
    data.put("pluginVersion", pluginVersion); // Append the version of the plugin
    JSONArray customCharts = new JSONArray();
    for (CustomChart customChart : charts) {
        // Add the data of the custom charts
        JSONObject chart = customChart.getRequestJsonObject();
        if (chart == null) { // If the chart is null, we skip it
            continue;
        }
        customCharts.add(chart);
    }
    data.put("customCharts", customCharts);

    return data;
}
 
开发者ID:CyR1en,项目名称:Minecordbot,代码行数:28,代码来源:Metrics.java

示例3: getChartData

import org.json.simple.JSONArray; //导入方法依赖的package包/类
@Override
protected JSONObject getChartData() throws Exception {
	JSONObject data = new JSONObject();
	JSONObject values = new JSONObject();
	Map<String, Integer> map = callable.call();
	if (map == null || map.isEmpty()) {
		// Null = skip the chart
		return null;
	}
	for (Map.Entry<String, Integer> entry : map.entrySet()) {
		JSONArray categoryValues = new JSONArray();
		categoryValues.add(entry.getValue());
		values.put(entry.getKey(), categoryValues);
	}
	data.put("values", values);
	return data;
}
 
开发者ID:RadBuilder,项目名称:EmojiChat,代码行数:18,代码来源:Metrics.java

示例4: processRequest

import org.json.simple.JSONArray; //导入方法依赖的package包/类
@Override
JSONStreamAware processRequest(HttpServletRequest req) throws NxtException {

    long assetId = ParameterParser.getAsset(req).getId();
    int firstIndex = ParameterParser.getFirstIndex(req);
    int lastIndex = ParameterParser.getLastIndex(req);

    JSONArray orders = new JSONArray();
    try (DbIterator<Order.Ask> askOrders = Order.Ask.getSortedOrders(assetId, firstIndex, lastIndex)) {
        while (askOrders.hasNext()) {
            orders.add(JSONData.askOrder(askOrders.next()));
        }
    }

    JSONObject response = new JSONObject();
    response.put("askOrders", orders);
    return response;

}
 
开发者ID:muhatzg,项目名称:burstcoin,代码行数:20,代码来源:GetAskOrders.java

示例5: allSetPermissionsToJSON

import org.json.simple.JSONArray; //导入方法依赖的package包/类
/**
 * Handles the work of converting all set permissions to JSON.
 * 
 * @param nodeRef NodeRef
 * @return JSONArray
 */
@SuppressWarnings("unchecked")
protected JSONArray allSetPermissionsToJSON(NodeRef nodeRef)
{
    Set<AccessPermission> acls = permissionService.getAllSetPermissions(nodeRef);
    JSONArray permissions = new JSONArray();

    List<AccessPermission> ordered = ScriptNode.getSortedACLs(acls);

    for (AccessPermission permission : ordered)
    {
        StringBuilder buf = new StringBuilder(64);
        buf.append(permission.getAccessStatus())
            .append(';')
            .append(permission.getAuthority())
            .append(';')
            .append(permission.getPermission())
            .append(';').append(permission.isSetDirectly() ? "DIRECT" : "INHERITED");                
        permissions.add(buf.toString());
    }
    return permissions;
}
 
开发者ID:Alfresco,项目名称:alfresco-repository,代码行数:28,代码来源:JSONConversionComponent.java

示例6: getChartData

import org.json.simple.JSONArray; //导入方法依赖的package包/类
@Override
protected JSONObject getChartData() {
    JSONObject data = new JSONObject();
    JSONObject values = new JSONObject();
    HashMap<String, Integer> map = getValues(new HashMap<String, Integer>());
    if (map == null || map.isEmpty()) {
        // Null = skip the chart
        return null;
    }
    for (Map.Entry<String, Integer> entry : map.entrySet()) {
        JSONArray categoryValues = new JSONArray();
        categoryValues.add(entry.getValue());
        values.put(entry.getKey(), categoryValues);
    }
    data.put("values", values);
    return data;
}
 
开发者ID:Soldier233,项目名称:ArchersBattle,代码行数:18,代码来源:Metrics.java

示例7: processRequest

import org.json.simple.JSONArray; //导入方法依赖的package包/类
@Override
JSONStreamAware processRequest(HttpServletRequest req) throws NxtException {
	
	Account account = ParameterParser.getAccount(req);
	
	List<Long> atIds = AT.getATsIssuedBy(account.getId());
	JSONArray ats = new JSONArray();
	for(long atId : atIds) {
		ats.add(JSONData.at(AT.getAT(atId)));
	}
	
	JSONObject response = new JSONObject();
       response.put("ats", ats);
       return response;
}
 
开发者ID:muhatzg,项目名称:burstcoin,代码行数:16,代码来源:GetAccountATs.java

示例8: asJSON

import org.json.simple.JSONArray; //导入方法依赖的package包/类
/**
 * Generates a JSON array from the snippets.
 *
 * @return The snippets as a JSON array.
 */
public JSONArray asJSON() {
    JSONArray array = new JSONArray();

    for (MessageSnippet snippet : this) {
        array.add(snippet.asJSON());
    }

    return array;
}
 
开发者ID:Fylipp,项目名称:easy-http-console,代码行数:15,代码来源:MessageContent.java

示例9: getChartData

import org.json.simple.JSONArray; //导入方法依赖的package包/类
@Override
protected JSONObject getChartData() throws Exception {
    final JSONObject data = new JSONObject();
    final JSONObject values = new JSONObject();
    final Map<String, int[]> map = this.callable.call();
    if (map == null || map.isEmpty()) {
        // Null = skip the chart
        return null;
    }
    boolean allSkipped = true;
    for (final Map.Entry<String, int[]> entry : map.entrySet()) {
        if (entry.getValue().length == 0) {
            continue; // Skip this invalid
        }
        allSkipped = false;
        final JSONArray categoryValues = new JSONArray();
        for (int categoryValue : entry.getValue()) {
            categoryValues.add(categoryValue);
        }
        values.put(entry.getKey(), categoryValues);
    }
    if (allSkipped) {
        // Null = skip the chart
        return null;
    }
    data.put("values", values);
    return data;
}
 
开发者ID:Shynixn,项目名称:BlockBall,代码行数:29,代码来源:Metrics.java

示例10: addArray

import org.json.simple.JSONArray; //导入方法依赖的package包/类
/**
 * Add float array of JSON key-value pairs
 * 
 * @param keyPath key path
 * @param keyValues the key values
 * @return this instance
 * @throws JsonException
 */
@PublicAtsApi
@SuppressWarnings( "unchecked")
public JsonText addArray( String keyPath, float[] keyValues ) throws JsonException {

    JSONArray jsonArray = new JSONArray();
    for (float keyValue : keyValues) {
        jsonArray.add(keyValue);
    }

    this.jsonObject.put(keyPath, jsonArray);
    return this;
}
 
开发者ID:Axway,项目名称:ats-framework,代码行数:21,代码来源:JsonText.java

示例11: processRequest

import org.json.simple.JSONArray; //导入方法依赖的package包/类
@Override
JSONStreamAware processRequest(JSONObject request, Peer peer) {

    JSONObject response = new JSONObject();

    List<Block> nextBlocks = new ArrayList<>();
    int totalLength = 0;
    long blockId = Convert.parseUnsignedLong((String) request.get("blockId"));
    List<? extends Block> blocks = Nxt.getBlockchain().getBlocksAfter(blockId, 1440);

    for (Block block : blocks) {
        int length = Constants.BLOCK_HEADER_LENGTH + block.getPayloadLength();
        if (totalLength + length > 1048576) {
            break;
        }
        nextBlocks.add(block);
        totalLength += length;
    }

    JSONArray nextBlocksArray = new JSONArray();
    for (Block nextBlock : nextBlocks) {
        nextBlocksArray.add(nextBlock.getJSONObject());
    }
    response.put("nextBlocks", nextBlocksArray);

    return response;
}
 
开发者ID:muhatzg,项目名称:burstcoin,代码行数:28,代码来源:GetNextBlocks.java

示例12: handleRequest

import org.json.simple.JSONArray; //导入方法依赖的package包/类
String handleRequest(JsonRequest request) throws Exception
   {
String output = "";
JSONArray filelist = new JSONArray();

File base = new File(request.getString("path", "/"));
if (!base.exists() || !base.isDirectory()) {
    throw new FileNotFoundException("Couldn't find [" + request + "]");
}
File[] files = base.listFiles();
Arrays.sort(files, new Comparator<File>() { 
	public int compare(File o1, File o2) {
	    if (o1.isDirectory() != o2.isDirectory()) {
		if (o1.isDirectory()) {
		    return -1;
		} else {
		    return 1;
		}
	    }
	    return o1.getName().compareToIgnoreCase(o2.getName());
	} 
    });

for (File f : files) {
    JSONObject o = new JSONObject();
    o.put("file", f.getName());
    o.put("type", f.isDirectory() ? "D" : "F");
    o.put("path", f.getCanonicalPath());
    filelist.add(o);
}
return JSONValue.toJSONString(filelist);
   }
 
开发者ID:l294265421,项目名称:ZooKeeper,代码行数:33,代码来源:Fs.java

示例13: processRequest

import org.json.simple.JSONArray; //导入方法依赖的package包/类
@Override
JSONStreamAware processRequest(HttpServletRequest req) {

    String accountIdString = Convert.emptyToNull(req.getParameter("account"));
    long accountId = 0;

    if (accountIdString != null) {
        try {
            accountId = Convert.parseAccountId(accountIdString);
        } catch (RuntimeException e) {
            return INCORRECT_ACCOUNT;
        }
    }

    JSONArray transactionIds = new JSONArray();
    try (DbIterator<? extends Transaction> transactionsIterator = Nxt.getTransactionProcessor().getAllUnconfirmedTransactions()) {
        while (transactionsIterator.hasNext()) {
            Transaction transaction = transactionsIterator.next();
            if (accountId != 0 && !(accountId == transaction.getSenderId() || accountId == transaction.getRecipientId())) {
                continue;
            }
            transactionIds.add(transaction.getStringId());
        }
    }

    JSONObject response = new JSONObject();
    response.put("unconfirmedTransactionIds", transactionIds);
    return response;
}
 
开发者ID:muhatzg,项目名称:burstcoin,代码行数:30,代码来源:GetUnconfirmedTransactionIds.java

示例14: saveCropList

import org.json.simple.JSONArray; //导入方法依赖的package包/类
/**
 * Save crop list in the ground truth.
 *
 * @param cropList - the list of crops to be saved
 * @param objId - the id of the object for which the crops are saved
 */
private JSONArray saveCropList(List<CropObject> cropList, long objId) {
    JSONArray cropsArray = new JSONArray();

    // make sure the input is correct
    if (cropList == null) {
        return cropsArray;
    }

    // save each crop
    for (CropObject cropObject : cropList) {
        String scribbleMapPathCrop = gtFilePath + "_scribb_" + objId + "_" + cropList.indexOf(cropObject) + ".ser";

        // save crop data in files and ground truth            
        // save scribbleMap
        saveCropScribblesFile(scribbleMapPathCrop, cropObject);

        // save data in the ground truth
        Rectangle pos = cropObject.getPositionOrig();

        if (pos != null) {
            JSONObject crop = new JSONObject();

            crop.put("scribble_map_path", scribbleMapPathCrop);
            crop.put(POSITION_X, pos.x);
            crop.put(POSITION_Y, pos.y);
            crop.put(WIDTH, pos.width);
            crop.put(HEIGHT, pos.height);

            cropsArray.add(crop);
        }
    }

    return cropsArray;
}
 
开发者ID:buni-rock,项目名称:Pixie,代码行数:41,代码来源:JSONDataManager.java

示例15: sendToSomePeers

import org.json.simple.JSONArray; //导入方法依赖的package包/类
public static void sendToSomePeers(List<Transaction> transactions) {
    JSONObject request = new JSONObject();
    JSONArray transactionsData = new JSONArray();
    for (Transaction transaction : transactions) {
        transactionsData.add(transaction.getJSONObject());
    }
    Logger.logDebugMessage("Forwarding " + transactions.size() + " Transactions to some peers" );
    request.put("requestType", "processTransactions");
    request.put("transactions", transactionsData);
    sendToSomePeers(request);
}
 
开发者ID:muhatzg,项目名称:burstcoin,代码行数:12,代码来源:Peers.java


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