• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java JSON类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中nxt.util.JSON的典型用法代码示例。如果您正苦于以下问题:Java JSON类的具体用法?Java JSON怎么用?Java JSON使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



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

示例1: getNextBlocks

import nxt.util.JSON; //导入依赖的package包/类
private JSONArray getNextBlocks(Peer peer, long curBlockId) {

			JSONObject request = new JSONObject();
			request.put("requestType", "getNextBlocks");
			request.put("blockId", Convert.toUnsignedLong(curBlockId));
			JSONObject response = peer.send(JSON.prepareRequest(request));
			if (response == null) {
				return null;
			}

			JSONArray nextBlocks = (JSONArray) response.get("nextBlocks");
			if (nextBlocks == null) {
				return null;
			}
			// prevent overloading with blocks
			if (nextBlocks.size() > 1440) {
				Logger.logDebugMessage("Obsolete or rogue peer " + peer.getPeerAddress() + " sends too many nextBlocks, blacklisting");
				peer.blacklist();
				return null;
			}

			return nextBlocks;

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


示例2: processPendingResponses

import nxt.util.JSON; //导入依赖的package包/类
synchronized void processPendingResponses(HttpServletRequest req, HttpServletResponse resp) throws IOException {
    JSONArray responses = new JSONArray();
    JSONStreamAware pendingResponse;
    while ((pendingResponse = pendingResponses.poll()) != null) {
        responses.add(pendingResponse);
    }
    if (responses.size() > 0) {
        JSONObject combinedResponse = new JSONObject();
        combinedResponse.put("responses", responses);
        if (asyncContext != null) {
            asyncContext.getResponse().setContentType("text/plain; charset=UTF-8");
            try (Writer writer = asyncContext.getResponse().getWriter()) {
                combinedResponse.writeJSONString(writer);
            }
            asyncContext.complete();
            asyncContext = req.startAsync();
            asyncContext.addListener(new UserAsyncListener());
            asyncContext.setTimeout(5000);
        } else {
            resp.setContentType("text/plain; charset=UTF-8");
            try (Writer writer = resp.getWriter()) {
                combinedResponse.writeJSONString(writer);
            }
        }
    } else {
        if (asyncContext != null) {
            asyncContext.getResponse().setContentType("text/plain; charset=UTF-8");
            try (Writer writer = asyncContext.getResponse().getWriter()) {
                JSON.emptyJSON.writeJSONString(writer);
            }
            asyncContext.complete();
        }
        asyncContext = req.startAsync();
        asyncContext.addListener(new UserAsyncListener());
        asyncContext.setTimeout(5000);
    }
}
 
开发者ID:muhatzg,项目名称:burstcoin,代码行数:38,代码来源:User.java


示例3: processRequest

import nxt.util.JSON; //导入依赖的package包/类
@Override
JSONStreamAware processRequest(HttpServletRequest req) {
    String id = Convert.emptyToNull(req.getParameter("id"));
    if (id == null) {
        return JSON.emptyJSON;
    }
    JSONObject response = new JSONObject();
    BigInteger bigInteger = new BigInteger(id);
    if (bigInteger.signum() < 0) {
        if (bigInteger.negate().compareTo(Convert.two64) > 0) {
            response.put("error", "overflow");
        } else {
            response.put("stringId", bigInteger.add(Convert.two64).toString());
            response.put("longId", String.valueOf(bigInteger.longValue()));
        }
    } else {
        if (bigInteger.compareTo(Convert.two64) >= 0) {
            response.put("error", "overflow");
        } else {
            response.put("stringId", bigInteger.toString());
            response.put("longId", String.valueOf(bigInteger.longValue()));
        }
    }
    return response;
}
 
开发者ID:muhatzg,项目名称:burstcoin,代码行数:26,代码来源:LongConvert.java


示例4: processRequest

import nxt.util.JSON; //导入依赖的package包/类
@Override
JSONStreamAware processRequest(final JSONObject request, final Peer peer) {
    if (Nxt.getBlockchain().getLastBlock().getStringId().equals(request.get("previousBlock"))) {
        Peers.peersService.submit(new Runnable() {
            @Override
            public void run() {
                try {
                    Nxt.getBlockchainProcessor().processPeerBlock(request);
                } catch (NxtException | RuntimeException e) {
                    if (peer != null) {
                        peer.blacklist(e);
                    }
                }
            }
        });
    }
    return JSON.emptyJSON;
}
 
开发者ID:giannisKonst,项目名称:blockchain,代码行数:19,代码来源:ProcessBlock.java


示例5: getNextBlocks

import nxt.util.JSON; //导入依赖的package包/类
private JSONArray getNextBlocks(Peer peer, long curBlockId) {

            JSONObject request = new JSONObject();
            request.put("requestType", "getNextBlocks");
            request.put("blockId", Convert.toUnsignedLong(curBlockId));
            JSONObject response = peer.send(JSON.prepareRequest(request));
            if (response == null) {
                return null;
            }

            JSONArray nextBlocks = (JSONArray) response.get("nextBlocks");
            if (nextBlocks == null) {
                return null;
            }
            /*
            // prevent overloading with blocks
            if (nextBlocks.size() > 720) {
                Logger.logDebugMessage("Obsolete or rogue peer " + peer.getPeerAddress() + " sends too many nextBlocks, blacklisting");
                peer.blacklist();
                return null;
            }*/

            return nextBlocks;

        }
 
开发者ID:giannisKonst,项目名称:blockchain,代码行数:26,代码来源:GetBlocksFromPeers.java


示例6: processRequest

import nxt.util.JSON; //导入依赖的package包/类
@Override
JSONStreamAware processRequest(HttpServletRequest req) throws NxtException {
    Poll poll = ParameterParser.getPoll(req);
    Account account = ParameterParser.getAccount(req);
    boolean includeWeights = "true".equalsIgnoreCase(req.getParameter("includeWeights"));
    Vote vote = Vote.getVote(poll.getId(), account.getId());
    if (vote != null) {
        int countHeight;
        JSONData.VoteWeighter weighter = null;
        if (includeWeights && (countHeight = Math.min(poll.getFinishHeight(), Nxt.getBlockchain().getHeight()))
                >= Nxt.getBlockchainProcessor().getMinRollbackHeight()) {
            VoteWeighting voteWeighting = poll.getVoteWeighting();
            VoteWeighting.VotingModel votingModel = voteWeighting.getVotingModel();
            weighter = voterId -> votingModel.calcWeight(voteWeighting, voterId, countHeight);
        }
        return JSONData.vote(vote, weighter);
    }
    return JSON.emptyJSON;
}
 
开发者ID:BitcoinFullnode,项目名称:ROKOS-OK-Bitcoin-Fullnode,代码行数:20,代码来源:GetPollVote.java


示例7: processRequest

import nxt.util.JSON; //导入依赖的package包/类
@Override
JSONStreamAware processRequest(HttpServletRequest req) {
    String id = Convert.emptyToNull(req.getParameter("id"));
    if (id == null) {
        return JSON.emptyJSON;
    }
    JSONObject response = new JSONObject();
    BigInteger bigInteger = new BigInteger(id);
    if (bigInteger.signum() < 0) {
        if (bigInteger.negate().compareTo(Convert.two64) > 0) {
            return JSONResponses.OVERFLOW;
        } else {
            response.put("stringId", bigInteger.add(Convert.two64).toString());
            response.put("longId", String.valueOf(bigInteger.longValue()));
        }
    } else {
        if (bigInteger.compareTo(Convert.two64) >= 0) {
            return JSONResponses.OVERFLOW;
        } else {
            response.put("stringId", bigInteger.toString());
            response.put("longId", String.valueOf(bigInteger.longValue()));
        }
    }
    return response;
}
 
开发者ID:BitcoinFullnode,项目名称:ROKOS-OK-Bitcoin-Fullnode,代码行数:26,代码来源:LongConvert.java


示例8: processRequest

import nxt.util.JSON; //导入依赖的package包/类
@Override
JSONStreamAware processRequest(JSONObject request, Peer peer) {

    List<String> exclude = (List<String>)request.get("exclude");
    if (exclude == null) {
        return JSON.emptyJSON;
    }

    JSONArray transactionsData = new JSONArray();
    try (DbIterator<? extends Transaction> transactions = Nxt.getTransactionProcessor().getAllUnconfirmedTransactions()) {
        while (transactions.hasNext()) {
            if (transactionsData.size() >= 100) {
                break;
            }
            Transaction transaction = transactions.next();
            if (Collections.binarySearch(exclude, transaction.getStringId()) < 0) {
                transactionsData.add(transaction.getJSONObject());
            }
        }
    }
    JSONObject response = new JSONObject();
    response.put("unconfirmedTransactions", transactionsData);

    return response;
}
 
开发者ID:BitcoinFullnode,项目名称:ROKOS-OK-Bitcoin-Fullnode,代码行数:26,代码来源:GetUnconfirmedTransactions.java


示例9: processRequest

import nxt.util.JSON; //导入依赖的package包/类
@Override
JSONStreamAware processRequest(final JSONObject request, final Peer peer) {
    String previousBlockId = (String)request.get("previousBlock");
    Block lastBlock = Nxt.getBlockchain().getLastBlock();
    if (lastBlock.getStringId().equals(previousBlockId) ||
            (Convert.parseUnsignedLong(previousBlockId) == lastBlock.getPreviousBlockId()
                    && lastBlock.getTimestamp() > Convert.parseLong(request.get("timestamp")))) {
        Peers.peersService.submit(() -> {
            try {
                Nxt.getBlockchainProcessor().processPeerBlock(request);
            } catch (NxtException | RuntimeException e) {
                if (peer != null) {
                    peer.blacklist(e);
                }
            }
        });
    }
    return JSON.emptyJSON;
}
 
开发者ID:BitcoinFullnode,项目名称:ROKOS-OK-Bitcoin-Fullnode,代码行数:20,代码来源:ProcessBlock.java


示例10: processRequest

import nxt.util.JSON; //导入依赖的package包/类
@Override
JSONStreamAware processRequest(JSONObject request, Peer peer) {
    final JSONArray peers = (JSONArray)request.get("peers");
    if (peers != null && Peers.getMorePeers && !Peers.hasTooManyKnownPeers()) {
        Peers.peersService.submit(() -> {
            for (Object announcedAddress : peers) {
                Peer newPeer = Peers.findOrCreatePeer((String) announcedAddress, true);
                if (newPeer != null) {
                    Peers.addPeer(newPeer);
                    if (Peers.hasTooManyKnownPeers()) {
                        break;
                    }
                }
            }
        });
    }
    return JSON.emptyJSON;
}
 
开发者ID:BitcoinFullnode,项目名称:ROKOS-OK-Bitcoin-Fullnode,代码行数:19,代码来源:AddPeers.java


示例11: getNextBlocks

import nxt.util.JSON; //导入依赖的package包/类
private JSONArray getNextBlocks(Peer peer, long curBlockId) {

            JSONObject request = new JSONObject();
            request.put("requestType", "getNextBlocks");
            request.put("blockId", Convert.toUnsignedLong(curBlockId));
            JSONObject response = peer.send(JSON.prepareRequest(request));
            if (response == null) {
                return null;
            }

            JSONArray nextBlocks = (JSONArray) response.get("nextBlocks");
            if (nextBlocks == null) {
                return null;
            }
            // prevent overloading with blocks
            if (nextBlocks.size() > 720) {
                Logger.logDebugMessage("Obsolete or rogue peer " + peer.getPeerAddress() + " sends too many nextBlocks, blacklisting");
                peer.blacklist();
                return null;
            }

            return nextBlocks;

        }
 
开发者ID:Ziftr,项目名称:nxt,代码行数:25,代码来源:BlockchainProcessorImpl.java


示例12: getNextBlocks

import nxt.util.JSON; //导入依赖的package包/类
private JSONArray getNextBlocks(Peer peer, Long curBlockId) {

            JSONObject request = new JSONObject();
            request.put("requestType", "getNextBlocks");
            request.put("blockId", Convert.toUnsignedLong(curBlockId));
            JSONObject response = peer.send(JSON.prepareRequest(request));
            if (response == null) {
                return null;
            }

            JSONArray nextBlocks = (JSONArray) response.get("nextBlocks");
            if (nextBlocks == null) {
                return null;
            }
            // prevent overloading with blocks
            if (nextBlocks.size() > 1440) {
                Logger.logDebugMessage("Obsolete or rogue peer " + peer.getPeerAddress() + " sends too many nextBlocks, blacklisting");
                peer.blacklist();
                return null;
            }

            return nextBlocks;

        }
 
开发者ID:aspnmy,项目名称:NasCoin,代码行数:25,代码来源:BlockchainProcessorImpl.java


示例13: processRequest

import nxt.util.JSON; //导入依赖的package包/类
@Override
JSONStreamAware processRequest(HttpServletRequest req) {

    String alias = req.getParameter("alias");
    if (alias == null) {
        return MISSING_ALIAS;
    }

    Alias aliasData = Alias.getAlias(alias.toLowerCase());
    if (aliasData == null) {
        return UNKNOWN_ALIAS;
    }

    if (aliasData.getURI().length() > 0) {

        JSONObject response = new JSONObject();
        response.put("uri", aliasData.getURI());
        return response;

    } else {
        return JSON.emptyJSON;
    }
}
 
开发者ID:aspnmy,项目名称:NasCoin,代码行数:24,代码来源:GetAliasURI.java


示例14: getNextBlocks

import nxt.util.JSON; //导入依赖的package包/类
private JSONArray getNextBlocks(Peer paramAnonymousPeer, Long paramAnonymousLong)
{
  JSONObject localJSONObject1 = new JSONObject();
  localJSONObject1.put("requestType", "getNextBlocks");
  localJSONObject1.put("blockId", Convert.toUnsignedLong(paramAnonymousLong));
  JSONObject localJSONObject2 = paramAnonymousPeer.send(JSON.prepareRequest(localJSONObject1));
  if (localJSONObject2 == null) {
    return null;
  }
  JSONArray localJSONArray = (JSONArray)localJSONObject2.get("nextBlocks");
  if (localJSONArray == null) {
    return null;
  }
  if (localJSONArray.size() > 1440)
  {
    Logger.logDebugMessage("Obsolete or rogue peer " + paramAnonymousPeer.getPeerAddress() + " sends too many nextBlocks, blacklisting");
    paramAnonymousPeer.blacklist();
    return null;
  }
  return localJSONArray;
}
 
开发者ID:stevedoe,项目名称:nxt-client,代码行数:22,代码来源:BlockchainProcessorImpl.java


示例15: processRequest

import nxt.util.JSON; //导入依赖的package包/类
JSONStreamAware processRequest(HttpServletRequest paramHttpServletRequest)
{
  String str = paramHttpServletRequest.getParameter("account");
  if (str == null) {
    return JSONResponses.MISSING_ACCOUNT;
  }
  Account localAccount;
  try
  {
    localAccount = Account.getAccount(Convert.parseUnsignedLong(str));
  }
  catch (RuntimeException localRuntimeException)
  {
    return JSONResponses.INCORRECT_ACCOUNT;
  }
  if (localAccount == null) {
    return JSONResponses.UNKNOWN_ACCOUNT;
  }
  if (localAccount.getPublicKey() != null)
  {
    JSONObject localJSONObject = new JSONObject();
    localJSONObject.put("publicKey", Convert.toHexString(localAccount.getPublicKey()));
    return localJSONObject;
  }
  return JSON.emptyJSON;
}
 
开发者ID:stevedoe,项目名称:nxt-client,代码行数:27,代码来源:GetAccountPublicKey.java


示例16: processRequest

import nxt.util.JSON; //导入依赖的package包/类
JSONStreamAware processRequest(HttpServletRequest paramHttpServletRequest)
{
  String str = paramHttpServletRequest.getParameter("alias");
  if (str == null) {
    return JSONResponses.MISSING_ALIAS;
  }
  Alias localAlias = Alias.getAlias(str.toLowerCase());
  if (localAlias == null) {
    return JSONResponses.UNKNOWN_ALIAS;
  }
  if (localAlias.getURI().length() > 0)
  {
    JSONObject localJSONObject = new JSONObject();
    localJSONObject.put("uri", localAlias.getURI());
    return localJSONObject;
  }
  return JSON.emptyJSON;
}
 
开发者ID:stevedoe,项目名称:nxt-client,代码行数:19,代码来源:GetAliasURI.java


示例17: getCommonBlockId

import nxt.util.JSON; //导入依赖的package包/类
private long getCommonBlockId(Peer peer, long commonBlockId) {

			while (true) {
				JSONObject request = new JSONObject();
				request.put("requestType", "getNextBlockIds");
				request.put("blockId", Convert.toUnsignedLong(commonBlockId));
				JSONObject response = peer.send(JSON.prepareRequest(request));
				if (response == null) {
					return 0;
				}
				JSONArray nextBlockIds = (JSONArray) response.get("nextBlockIds");
				if (nextBlockIds == null || nextBlockIds.size() == 0) {
					return 0;
				}
				// prevent overloading with blockIds
				if (nextBlockIds.size() > 1440) {
					Logger.logDebugMessage("Obsolete or rogue peer " + peer.getPeerAddress() + " sends too many nextBlockIds, blacklisting");
					peer.blacklist();
					return 0;
				}

				for (Object nextBlockId : nextBlockIds) {
					long blockId = Convert.parseUnsignedLong((String) nextBlockId);
					if (! BlockDb.hasBlock(blockId)) {
						return commonBlockId;
					}
					commonBlockId = blockId;
				}
			}

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


示例18: onError

import nxt.util.JSON; //导入依赖的package包/类
@Override
public void onError(AsyncEvent asyncEvent) throws IOException {

    synchronized (User.this) {
        asyncContext.getResponse().setContentType("text/plain; charset=UTF-8");

        try (Writer writer = asyncContext.getResponse().getWriter()) {
            JSON.emptyJSON.writeJSONString(writer);
        }

        asyncContext.complete();
        asyncContext = null;
    }

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


示例19: onTimeout

import nxt.util.JSON; //导入依赖的package包/类
@Override
public void onTimeout(AsyncEvent asyncEvent) throws IOException {

    synchronized (User.this) {
        asyncContext.getResponse().setContentType("text/plain; charset=UTF-8");

        try (Writer writer = asyncContext.getResponse().getWriter()) {
            JSON.emptyJSON.writeJSONString(writer);
        }

        asyncContext.complete();
        asyncContext = null;
    }

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


示例20: processRequest

import nxt.util.JSON; //导入依赖的package包/类
@Override
JSONStreamAware processRequest(HttpServletRequest req) throws NxtException {

    Account account = ParameterParser.getAccount(req);

    if (account.getPublicKey() != null) {
        JSONObject response = new JSONObject();
        response.put("publicKey", Convert.toHexString(account.getPublicKey()));
        return response;
    } else {
        return JSON.emptyJSON;
    }
}
 
开发者ID:muhatzg,项目名称:burstcoin,代码行数:14,代码来源:GetAccountPublicKey.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java GetApplicationAttemptsResponseProto类代码示例发布时间:2022-05-23
下一篇:
Java Users类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap