本文整理汇总了Java中net.minidev.json.JSONArray.add方法的典型用法代码示例。如果您正苦于以下问题:Java JSONArray.add方法的具体用法?Java JSONArray.add怎么用?Java JSONArray.add使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类net.minidev.json.JSONArray
的用法示例。
在下文中一共展示了JSONArray.add方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testbrokenLink
import net.minidev.json.JSONArray; //导入方法依赖的package包/类
@Test
public void testbrokenLink() throws IOException, URISyntaxException {
JSONObject object = new JSONObject();
object.put("key", "sprSCKKWf8xUeXxEo6Bv0lE1sSjWRDkO");
object.put("marketName", "eoemarket");
object.put("count", 1);
JSONArray data = new JSONArray();
JSONObject o = new JSONObject();
o.put("id", -1);
o.put("link", "http://testsssssss");
o.put("statusCode", 404);
data.add(o);
object.put("data", data);
String test = "eyJjb3VudCI6IDEwLCAibWFya2V0TmFtZSI6ICJBcHBDaGluYSIsICJkYXRhIjogW3sibGluayI6ICJodHRwOi8vd3d3LmFwcGNoaW5hLmNvbS9hcHAvY29tLmdvb2dsZS5hbmRyb2lkLmFwcHMubWFwcyIsICJpZCI6IDEsICJzdGF0dXNDb2RlIjogNDA0fSwgeyJsaW5rIjogImh0dHA6Ly93d3cuYXBwY2hpbmEuY29tL2FwcC9jb20ud2VhdGhlci5XZWF0aGVyIiwgImlkIjogMiwgInN0YXR1c0NvZGUiOiA0MDR9LCB7ImxpbmsiOiAiaHR0cDovL3d3dy5hcHBjaGluYS5jb20vYXBwL2NvbS5zdHlsZW0ud2FsbHBhcGVycyIsICJpZCI6IDQsICJzdGF0dXNDb2RlIjogNDA0fSwgeyJsaW5rIjogImh0dHA6Ly93d3cuYXBwY2hpbmEuY29tL2FwcC9jb20uc2hhemFtLmVuY29yZS5hbmRyb2lkIiwgImlkIjogNSwgInN0YXR1c0NvZGUiOiA0MDR9LCB7ImxpbmsiOiAiaHR0cDovL3d3dy5hcHBjaGluYS5jb20vYXBwL2NvbS5yaW5nZHJvaWQiLCAiaWQiOiA2LCAic3RhdHVzQ29kZSI6IDQwNH0sIHsibGluayI6ICJodHRwOi8vd3d3LmFwcGNoaW5hLmNvbS9hcHAvY29tLnAxLmNob21wc21zIiwgImlkIjogNywgInN0YXR1c0NvZGUiOiA0MDR9LCB7ImxpbmsiOiAiaHR0cDovL3d3dy5hcHBjaGluYS5jb20vYXBwL2NvbS5oYW5kY2VudC5uZXh0c21zIiwgImlkIjogOCwgInN0YXR1c0NvZGUiOiA0MDR9LCB7ImxpbmsiOiAiaHR0cDovL3d3dy5hcHBjaGluYS5jb20vYXBwL2NvbS5mYWNlYm9vay5rYXRhbmEiLCAiaWQiOiA5LCAic3RhdHVzQ29kZSI6IDQwNH0sIHsibGluayI6ICJodHRwOi8vd3d3LmFwcGNoaW5hLmNvbS9hcHAvY29tLmNvZGUuaS5tdXNpYyIsICJpZCI6IDEwLCAic3RhdHVzQ29kZSI6IDQwNH0sIHsibGluayI6ICJodHRwOi8vd3d3LmFwcGNoaW5hLmNvbS9hcHAvY29tLmJpZ2d1LnNob3BzYXZ2eSIsICJpZCI6IDExLCAic3RhdHVzQ29kZSI6IDQwNH1dLCAia2V5IjogImpqRzhMa0MzTUh5RjlYY3NWS2g2Rkh4bXRMQ05ZdE14In0=";
Reader input = new StringReader(object.toJSONString());
byte[] binaryData = IOUtils.toByteArray(input, "UTF-8");
String encodeBase64 = Base64.encodeBase64String(binaryData);
System.out.println(encodeBase64);
String url = "http://localhost:9080/sjk-market-admin/market/brokenLink.d";
url = "http://app.sjk.ijinshan.com/market/brokenLink.d";
URIBuilder builder = new URIBuilder(url);
builder.setParameter("c", test);
DefaultHttpClient httpclient = new DefaultHttpClient();
HttpPost httpPost = new HttpPost(builder.build());
HttpResponse response = httpclient.execute(httpPost);
logger.debug("URI: {} , {}", url, response.getStatusLine());
HttpEntity entity = response.getEntity();
InputStream is = entity.getContent();
// be convinient to debug
String rspJSON = IOUtils.toString(is, "UTF-8");
System.out.println(rspJSON);
}
示例2: testbrokenLink
import net.minidev.json.JSONArray; //导入方法依赖的package包/类
@Test
public void testbrokenLink() throws IOException, URISyntaxException {
JSONObject object = new JSONObject();
object.put("key", "sprSCKKWf8xUeXxEo6Bv0lE1sSjWRDkO");
object.put("marketName", "eoemarket");
object.put("count", 1);
JSONArray data = new JSONArray();
JSONObject o = new JSONObject();
o.put("id", -1);
o.put("link", "http://testsssssss");
o.put("statusCode", 404);
data.add(o);
object.put("data", data);
Reader input = new StringReader(object.toJSONString());
byte[] binaryData = IOUtils.toByteArray(input, "UTF-8");
String encodeBase64 = Base64.encodeBase64String(binaryData);
String url = "http://localhost:8080/sjk-market/market/brokenLink.d";
url = "http://app-t.sjk.ijinshan.com/market/brokenLink.d";
URIBuilder builder = new URIBuilder(url);
builder.setParameter("c", encodeBase64);
DefaultHttpClient httpclient = new DefaultHttpClient();
HttpPost httpPost = new HttpPost(builder.build());
HttpResponse response = httpclient.execute(httpPost);
logger.debug("URI: {} , {}", url, response.getStatusLine());
HttpEntity entity = response.getEntity();
InputStream is = entity.getContent();
// be convinient to debug
String rspJSON = IOUtils.toString(is, "UTF-8");
System.out.println(rspJSON);
}
示例3: reportToJson
import net.minidev.json.JSONArray; //导入方法依赖的package包/类
public static String reportToJson(ResourceReport r) {
JSONObject json = new JSONObject();
json.put("start", r.getStart());
json.put("end", r.getEnd());
json.put("resource", r.getResource());
if (r.hasResourceID())
json.put("resourceID", r.getResourceID());
json.put("machine", r.getMachine());
json.put("processID", r.getProcessID());
if (r.hasProcessName())
json.put("processName", r.getProcessName());
if (r.hasUtilization())
json.put("utilization", r.getUtilization());
JSONArray reports = new JSONArray();
for (TenantOperationReport report : r.getTenantReportList()) {
reports.add(tenantReportToJSON(report));
}
json.put("tenantReports", reports);
return json.toString();
}
示例4: doGet
import net.minidev.json.JSONArray; //导入方法依赖的package包/类
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setContentType("text/json");
response.setStatus(HttpServletResponse.SC_OK);
String uri = request.getRequestURI();
int pathLen = request.getServletPath().length() + 1;
String tagsString = uri.length() > pathLen ? uri.substring(pathLen) : "";
String[] tags = tagsString.split(",");
JSONObject obj = new JSONObject();
for (String tag : tags) {
JSONArray arr = new JSONArray();
Collection<TaskRecord> taskInfos = metadata.getTasksByTag(tag, 0, Integer.MAX_VALUE);
for (TaskRecord t : taskInfos) {
arr.add(t.getTaskId().toString());
}
obj.put(tag, arr);
}
Writer out = response.getWriter();
out.write(obj.toJSONString());
}
示例5: modifyAnnotationContextArray
import net.minidev.json.JSONArray; //导入方法依赖的package包/类
/**
* Remove useless information about annotationContexts
* @param annotationContextArray annotationContextArray from ArangoDB
* @return modified array without good-for-nothing information
*/
private JSONArray modifyAnnotationContextArray(JSONArray annotationContextArray){
JSONArray modified = new JSONArray();
for (Object newJS:annotationContextArray){
//JSONObject newJS = (JSONObject) JSONValue.parse(edge);
JSONObject newAnnotationContext = (JSONObject) JSONValue.parse(newJS.toString());
newAnnotationContext.remove(new String("_id"));
newAnnotationContext.remove(new String("_key"));
newAnnotationContext.remove(new String("_rev"));
newAnnotationContext.remove(new String("_from"));
newAnnotationContext.remove(new String("_to"));
modified.add(newAnnotationContext);
}
return modified;
}
示例6: 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;
}
示例7: saveResults
import net.minidev.json.JSONArray; //导入方法依赖的package包/类
public void saveResults() {
expert2score = Application.sortByValue(node2pagescore);
JSONArray jsonArray = new JSONArray();
for (String userid : expert2score.keySet()) {
if (super.MAX_RESULTS > 0) {
UserEntity user = super.usermap.get(Long.parseLong(userid));
user.setScore(node2pagescore.get(userid));
ArrayList<String> labels = super.jcreator.getConnectedLabels(userid);
user.setRelatedPosts(labels);
if (user != null) {
jsonArray.add(user);
}
} else {
break;
}
super.MAX_RESULTS--;
}
experts = jsonArray.toJSONString();
super.save(expert2score, experts);
}
示例8: saveResults
import net.minidev.json.JSONArray; //导入方法依赖的package包/类
@Override
public void saveResults() {
expert2score = Application.sortByValue(node2hitsscore);
JSONArray jsonArray = new JSONArray();
for (String userid : expert2score.keySet()) {
// Restrict result to 10 items for now.
if (super.MAX_RESULTS > 0) {
UserEntity user = super.usermap.get(Long.parseLong(userid));
user.setScore(node2hitsscore.get(userid));
if (user != null) {
jsonArray.add(user);
}
super.MAX_RESULTS--;
}
}
experts = jsonArray.toJSONString();
super.save(expert2score, experts);
}
开发者ID:learning-layers,项目名称:Expert-Identification-Service,代码行数:24,代码来源:CommunityAwareHITSStrategy.java
示例9: saveResults
import net.minidev.json.JSONArray; //导入方法依赖的package包/类
public void saveResults() {
expert2score = Application.sortByValue(node2hitsscore);
JSONArray jsonArray = new JSONArray();
for (String userid : expert2score.keySet()) {
if (super.MAX_RESULTS > 0) {
UserEntity user = super.usermap.get(Long.parseLong(userid));
user.setScore(node2hitsscore.get(userid));
ArrayList<String> labels = super.jcreator.getConnectedLabels(userid);
user.setRelatedPosts(labels);
if (user != null) {
jsonArray.add(user);
}
} else {
break;
}
super.MAX_RESULTS--;
}
experts = jsonArray.toJSONString();
super.save(expert2score, experts);
}
示例10: saveResults
import net.minidev.json.JSONArray; //导入方法依赖的package包/类
@Override
public void saveResults() {
expert2score = Application.sortByValue(node2hitsscore);
int count = 0;
JSONArray jsonArray = new JSONArray();
for (String userid : expert2score.keySet()) {
// Restrict result to 10 items for now.
if (count < 10) {
UserEntity user = super.usermap.get(Long.parseLong(userid));
user.setScore(node2hitsscore.get(userid));
if (user != null) {
jsonArray.add(user);
} else {
break;
}
count++;
}
}
experts = jsonArray.toJSONString();
super.save(expert2score, experts);
}
示例11: runTest
import net.minidev.json.JSONArray; //导入方法依赖的package包/类
private void runTest() {
JSONObject result = new JSONObject();
JSONArray mustterms = queryUtil.createJA();
mustterms.add(queryUtil.term(ITQCoreOntology.RESOURCE_URL_PROPERTY, "http://worldmap.harvard.edu/"));
mustterms.add(queryUtil.term(ITQCoreOntology.INSTANCE_OF_PROPERTY_TYPE, INodeTypes.BOOKMARK_TYPE));
result.put("query", queryUtil.bool(queryUtil.must(mustterms)));
System.out.println("A "+result.toJSONString());
IResult r = tmEnvironment.getDatabase().runQuery(result.toJSONString(), 0, -1, credentials);
System.out.println("B "+r.getErrorString()+" | "+r.getResultObject());
}
示例12: encode
import net.minidev.json.JSONArray; //导入方法依赖的package包/类
@SuppressWarnings("rawtypes")
@Override
public JSONObject encode(IdPAttribute idpAttribute) throws AttributeEncodingException {
Constraint.isNotNull(idpAttribute, "Attribute to encode cannot be null");
String attributeString = "";
JSONObject obj = new JSONObject();
JSONArray array = new JSONArray();
for (IdPAttributeValue value : idpAttribute.getValues()) {
if (value instanceof ByteAttributeValue && value.getValue() != null) {
if (getAsInt()) {
// int
JSONArray innerArray = new JSONArray();
for (byte byteValue : ((ByteAttributeValue) value).getValue()) {
innerArray.add((int)byteValue);
}
// each byte array is converted to json int array and placed
// to json array.
array.add(innerArray);
} else {
// b64
if (attributeString.length() > 0 && getStringDelimiter() != null) {
attributeString += getStringDelimiter();
}
attributeString += Base64Support.encode(((ByteAttributeValue) value).getValue(),
Base64Support.UNCHUNKED);
if (getAsArray()) {
array.add(attributeString.toString());
attributeString = "";
}
}
}
}
if (getAsArray() || getAsInt()) {
obj.put(getName(), array.size() == 0 ? null : array);
} else {
obj.put(getName(), attributeString.toString().isEmpty() ? null : attributeString.toString());
}
return obj;
}
示例13: mapCustomersToJson
import net.minidev.json.JSONArray; //导入方法依赖的package包/类
public String mapCustomersToJson(List<Customer> customers, String requestUrl) {
JSONObject json = new JSONObject();
JSONArray jsonCustomers = new JSONArray();
for (Customer customer : customers) {
jsonCustomers.add(constructJsonCustomer(requestUrl, customer));
}
json.put("customers", jsonCustomers);
return json.toString();
}
示例14: parseFromJSONArray
import net.minidev.json.JSONArray; //导入方法依赖的package包/类
@Test
public void parseFromJSONArray() {
JSONArray scopeArray = new JSONArray();
scopeArray.add("scope1");
scopeArray.add("scope2");
scopeArray.add("scope3");
ScopeSet scopeSet = ScopeSet.parse(scopeArray);
assertTrue(scopeSet.size() == 3);
assertTrue(scopeSet.contains("scope1"));
}
示例15: getpeerinfo
import net.minidev.json.JSONArray; //导入方法依赖的package包/类
private Object getpeerinfo() {
JSONArray info = new JSONArray();
List<Peer> peers = kit.peerGroup().getConnectedPeers();
for (Peer p : peers) {
JSONObject peer = new JSONObject();
PeerAddress pad = p.getAddress();
peer.put("addr",pad.getAddr().getHostAddress() + ":" + pad.getPort());
info.add(peer);
}
return info;
}