net.sf.json.JSONArray.get()方法的使用及代码示例

x33g5p2x  于2022-01-21 转载在 其他  
字(13.3k)|赞(0)|评价(0)|浏览(129)

本文整理了Java中net.sf.json.JSONArray.get()方法的一些代码示例,展示了JSONArray.get()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。JSONArray.get()方法的具体详情如下:
包路径:net.sf.json.JSONArray
类名称:JSONArray
方法名:get

JSONArray.get介绍

暂无

代码示例

代码示例来源:origin: woder/TorchBot

public String formatColours(JSONArray arr) {
  String formated = "";
  for (int i = 0; i < arr.size(); i++) {
    if (arr.get(i).toString().contains("{")) {
      JSONObject ob = arr.getJSONObject(i);
      String key = ob.getString("color");
      String theText = ob.getString("text");
      formated = formated + ChatColor.COLOR_CHAR + attributes.get(key) + theText;
    } else {
      formated = formated + ChatColor.BLACK + arr.getString(i);
    }
  }
  return formated;
}

代码示例来源:origin: org.eclipse.hudson.main/hudson-core

/**
 * Write JSON array to writer in canonical form.
 *
 * @param json JSONArray
 * @param writer Writer
 * @throws IOException if any.
 */
public static void write(JSONArray json, Writer writer) throws IOException {
  boolean b = false;
  int len = json.size();
  writer.write('[');
  for (int i = 0; i < len; i += 1) {
    if (b) {
      writer.write(',');
    }
    Object v = json.get(i);
    if (v instanceof JSON) {
      write((JSON) v, writer);
    } else {
      writer.write(toCanonical(v));
    }
    b = true;
  }
  writer.write(']');
}

代码示例来源:origin: org.geoserver/gs-wms

@Test
public void testReprojectedLayer() throws Exception {
  String layer = getLayerId(MockData.MPOLYGONS);
  String request =
      "wms?version=1.1.1&bbox=500525,500025,500575,500050&styles=&format=jpeg"
          + "&request=GetFeatureInfo&layers="
          + layer
          + "&query_layers="
          + layer
          + "&width=20&height=20&x=10&y=10"
          + "&info_format="
          + JSONType.json;
  // JSON
  JSONObject json = (JSONObject) getAsJSON(request);
  JSONObject feature = (JSONObject) json.getJSONArray("features").get(0);
  JSONObject geom = feature.getJSONObject("geometry");
  // unroll the geometry and get the first coordinate
  JSONArray coords =
      geom.getJSONArray("coordinates").getJSONArray(0).getJSONArray(0).getJSONArray(0);
  assertTrue(
      new NumberRange<Double>(Double.class, 500525d, 500575d)
          .contains((Number) coords.getDouble(0)));
  assertTrue(
      new NumberRange<Double>(Double.class, 500025d, 500050d)
          .contains((Number) coords.getDouble(1)));
}

代码示例来源:origin: mbreese/couchdb4j

/**
 * Retrieves a list of documents that matched this View.
 * These documents only contain the data that the View has returned (not the full document).
 * <p>
 * You can load the remaining information from Document.reload();
 * 
 * @return
 */
public List<Document> getResults() {
  JSONArray ar = getJSONObject().getJSONArray("rows");
  List<Document> docs = new ArrayList<Document>(ar.size());
  for (int i=0 ; i< ar.size(); i++) {
    log.info(ar.getString(i));
    if (ar.get(i)!=null && !ar.getString(i).equals("null")) {
      Document d = new Document(ar.getJSONObject(i));
      d.setDatabase(database);
      docs.add(d);
    }
  }
  return docs;	
}

代码示例来源:origin: org.jvnet.hudson.main/hudson-core

/**
 * Write JSON array to writer in canonical form.
 *
 * @param json JSONArray
 * @param writer Writer
 * @throws IOException
 */
public static void write(JSONArray json, Writer writer) throws IOException {
  boolean b = false;
  int len = json.size();
  writer.write('[');
  for (int i = 0; i < len; i += 1) {
    if (b) {
      writer.write(',');
    }
    Object v = json.get(i);
    if (v instanceof JSON) {
      write((JSON) v, writer);
    } else {
      writer.write(toCanonical(v));
    }
    b = true;
  }
  writer.write(']');
}

代码示例来源:origin: org.eclipse.hudson/hudson-core

/**
 * Write JSON array to writer in canonical form.
 *
 * @param json JSONArray
 * @param writer Writer
 * @throws IOException if any.
 */
public static void write(JSONArray json, Writer writer) throws IOException {
  boolean b = false;
  int len = json.size();
  writer.write('[');
  for (int i = 0; i < len; i += 1) {
    if (b) {
      writer.write(',');
    }
    Object v = json.get(i);
    if (v instanceof JSON) {
      write((JSON) v, writer);
    } else {
      writer.write(toCanonical(v));
    }
    b = true;
  }
  writer.write(']');
}

代码示例来源:origin: blogchong/mite8-com

public static JSONArray pageOpt(JSONArray jsonArray, int page , int size) {
    JSONArray jsonArray1 = new JSONArray();
    if(page > 0) {
      for (int i = (page - 1) * size; i < page * size && i < jsonArray.size(); i++) {
        jsonArray1.add(jsonArray.get(i));
      }
    }
    return jsonArray1;
  }
}

代码示例来源:origin: RPTools/maptool

/**
 * Reverses a json array.
 * 
 * @param jsonArray
 *            The json array to reverse.
 * @return the reversed json array.
 * @throws ParserException
 *             if jsonArray is not a json array.
 */
private JSONArray JSONReverse(Object jsonArray) throws ParserException {
  if (!(jsonArray instanceof JSONArray)) {
    throw new ParserException(I18N.getText("macro.function.json.onlyArray", "json.reverse"));
  }
  // Create a new JSON Array to preserve immutable state for macros.
  JSONArray jarr = JSONArray.fromObject(jsonArray);
  List<Object> arr = new LinkedList<Object>();
  for (int i = jarr.size() - 1; i >= 0; i--) {
    arr.add(jarr.get(i));
  }
  return JSONArray.fromObject(arr);
}

代码示例来源:origin: Aresyi/smart-api

/**
 * 查询指定项目
 * @param moduleName
 * @param limit
 * @return
 */
public List<JSONObject> getItemByIds(JSONArray ids){
  DBCollection itemCollection = this.getItemCollection();
  
  BasicDBList values = new BasicDBList();
  
  for(int i=0;i<ids.size();i++){
    values.add(new ObjectId(ids.get(i).toString()));
  }
  
  DBObject query = new BasicDBObject();
  query.put("_id", new BasicDBObject("$in", values));
  
  return this.change2ListJSONObject(itemCollection.find(query));
}

代码示例来源:origin: edu.uiuc.ncsa.security/ncsa-security-util

protected void addArgs(JFunctor ff, JSONObject jsonObject) {
  JSONArray jsonArray = getArray(jsonObject);
  for (int i = 0; i < jsonArray.size(); i++) {
    Object obj = jsonArray.get(i);
    if ((obj instanceof JSONObject)) {
      ff.addArg(fromJSON((JSONObject) obj));
    } else {
      boolean isDone = false;
      // Special case short hand for logical constants
      if ((obj instanceof String) && (obj).equals("$true")) {
        ff.addArg(new jTrue());
        isDone = true;
      }
      if ((obj instanceof String) && (obj).equals("$false")) {
        ff.addArg(new jFalse());
        isDone = true;
      }
      if (!isDone) {
        // so if this argument is not $true or $false, then it's jsut a string and add it.
        ff.addArg(preprocess(obj.toString()));
      }
    }
  }
}

代码示例来源:origin: org.geoserver.community/gs-sfs

private void testAllBuildings(JSONObject collection) {
  assertEquals("FeatureCollection", collection.getString("type"));
  final JSONArray features = collection.getJSONArray("features");
  assertEquals(2 , features.size());
  JSONObject feature = (JSONObject) features.get(0);
  assertEquals("Feature", feature.getString("type"));
  assertEquals("113", feature.getJSONObject("properties").getString("FID"));
  feature = (JSONObject) features.get(1);
  assertEquals("Feature", feature.getString("type"));
  assertEquals("114", feature.getJSONObject("properties").getString("FID"));
}

代码示例来源:origin: stapler/stapler

public void testRaw() {
  RawBinding r = bind("{x:{a:true,b:1},y:[1,2,3]}", RawBinding.class);
  // array coercion on y
  RawBinding r2 = bind("{x:{a:true,b:1},y:{p:true}}", RawBinding.class);
  JSONObject o = (JSONObject)r2.y.get(0);
  assertTrue(o.getBoolean("p"));
  // array coercion on y
  RawBinding r3 = bind("{x:{a:true,b:1},y:true}", RawBinding.class);
  assertTrue((Boolean)r3.y.get(0));
}

代码示例来源:origin: org.geoserver.community/gs-sfs

private void testFirstBuilding(JSONObject collection) {
  assertEquals("FeatureCollection", collection.getString("type"));
  final JSONArray features = collection.getJSONArray("features");
  assertEquals(1 , features.size());
  JSONObject feature = (JSONObject) features.get(0);
  assertEquals("Feature", feature.getString("type"));
  assertEquals("113", feature.getJSONObject("properties").getString("FID"));
}

代码示例来源:origin: org.kohsuke.stapler/stapler

public boolean doDispatch(RequestImpl req, ResponseImpl rsp, Object node) throws IllegalAccessException, InvocationTargetException, ServletException, IOException {
  if (!req.isJavaScriptProxyCall())
    return false;
  req.stapler.getWebApp().getCrumbIssuer().validateCrumb(req,req.getHeader("Crumb"));
  Dispatcher.anonymizedTraceEval(req, rsp, node, "%s#%s", f.getName());
  if(traceable())
    trace(req,rsp,"-> <%s>.%s(...)",node, f.getName());
  JSONArray jsargs = JSONArray.fromObject(IOUtils.toString(req.getReader()));
  Object[] args = new Object[jsargs.size()];
  Class[] types = f.getParameterTypes();
  Type[] genericTypes = f.getGenericParameterTypes();
  if (args.length != types.length) {
    throw new IllegalArgumentException("argument count mismatch between " + jsargs + " and " + Arrays.toString(genericTypes));
  }
  for (int i=0; i<args.length; i++)
    args[i] = req.bindJSON(genericTypes[i],types[i],jsargs.get(i));
  return f.bindAndInvokeAndServeResponse(node,req,rsp,args);
}

代码示例来源:origin: stapler/stapler

public boolean doDispatch(RequestImpl req, ResponseImpl rsp, Object node) throws IllegalAccessException, InvocationTargetException, ServletException, IOException {
  if (!req.isJavaScriptProxyCall())
    return false;
  req.stapler.getWebApp().getCrumbIssuer().validateCrumb(req,req.getHeader("Crumb"));
  Dispatcher.anonymizedTraceEval(req, rsp, node, "%s#%s", f.getName());
  if(traceable())
    trace(req,rsp,"-> <%s>.%s(...)",node, f.getName());
  JSONArray jsargs = JSONArray.fromObject(IOUtils.toString(req.getReader()));
  Object[] args = new Object[jsargs.size()];
  Class[] types = f.getParameterTypes();
  Type[] genericTypes = f.getGenericParameterTypes();
  if (args.length != types.length) {
    throw new IllegalArgumentException("argument count mismatch between " + jsargs + " and " + Arrays.toString(genericTypes));
  }
  for (int i=0; i<args.length; i++)
    args[i] = req.bindJSON(genericTypes[i],types[i],jsargs.get(i));
  return f.bindAndInvokeAndServeResponse(node,req,rsp,args);
}

代码示例来源:origin: org.hudsonci.stapler/stapler-core

public boolean doDispatch(RequestImpl req, ResponseImpl rsp, Object node) throws IllegalAccessException, InvocationTargetException, ServletException, IOException {
  if (!req.isJavaScriptProxyCall())
    return false;
  req.stapler.getWebApp().getCrumbIssuer().validateCrumb(req,req.getHeader("Crumb"));
  if(traceable())
    trace(req,rsp,"-> <%s>.%s(...)",node, f.getName());
  JSONArray jsargs = JSONArray.fromObject(IOUtils.toString(req.getReader()));
  Object[] args = new Object[jsargs.size()];
  Class[] types = f.getParameterTypes();
  Type[] genericTypes = f.getParameterTypes();
  for (int i=0; i<args.length; i++)
    args[i] = req.bindJSON(genericTypes[i],types[i],jsargs.get(i));
  f.bindAndInvokeAndServeResponse(node,req,rsp,args);
  return true;
}

代码示例来源:origin: stapler/stapler

public void testNoopToReturnCopy() {
    JSONObject input = new JSONObject();
    input.accumulate("a", 1);
    input.accumulate("a", 2);
    input.accumulate("a", 3);
    input.accumulate("b", 4);
  
    JSONObject sub = new JSONObject();
    sub.accumulate("d", 5);
    input.accumulate("c", sub);
    
    JSONObject output = JsonInErrorMessageSanitizer.NOOP.sanitize(input);
    assertNotSame(output, input);
    assertEquals(output.getJSONArray("a").get(0), input.getJSONArray("a").get(0));
    assertEquals(output.getJSONArray("a").get(2), input.getJSONArray("a").get(2));
    assertEquals(output.getInt("b"), input.getInt("b"));
    assertEquals(output.getJSONObject("c").getInt("d"), input.getJSONObject("c").getInt("d"));
  }
}

代码示例来源:origin: org.geoserver.community/gs-sfs

@Test
public void testNoGeometry() throws Exception {
  MockHttpServletResponse response = getAsServletResponse(root() + "data/cite:Buildings?queryable=FID&FID__eq=113&no_geom=true");
  assertEquals(200, response.getStatusCode());
  assertEquals(MediaType.APPLICATION_JSON.getName(), response.getContentType());
  
  JSONObject collection = (JSONObject) json(response);
  // print(collection);
  assertEquals("FeatureCollection", collection.getString("type"));
  final JSONArray features = collection.getJSONArray("features");
  assertEquals(1 , features.size());
  JSONObject feature = (JSONObject) features.get(0);
  assertEquals("Feature", feature.getString("type"));
  assertFalse(feature.has("geometry"));
  final JSONObject properties = feature.getJSONObject("properties");
  assertEquals("113", properties.getString("FID"));
  assertEquals("123 Main Street", properties.getString("ADDRESS"));
}

代码示例来源:origin: org.geoserver.community/gs-sfs

@Test
public void testRestrictAttributes() throws Exception {
  MockHttpServletResponse response = getAsServletResponse(root() + "data/cite:Buildings?queryable=FID&FID__eq=113&attrs=FID");
  assertEquals(200, response.getStatusCode());
  assertEquals(MediaType.APPLICATION_JSON.getName(), response.getContentType());
  
  JSONObject collection = (JSONObject) json(response);
  // print(collection);
  assertEquals("FeatureCollection", collection.getString("type"));
  final JSONArray features = collection.getJSONArray("features");
  assertEquals(1 , features.size());
  JSONObject feature = (JSONObject) features.get(0);
  assertEquals("Feature", feature.getString("type"));
  assertTrue(feature.has("geometry"));
  final JSONObject properties = feature.getJSONObject("properties");
  assertEquals("113", properties.getString("FID"));
  assertFalse(properties.has("ADDRESS"));
}

代码示例来源:origin: uber/phabricator-jenkins-plugin

@Override
  public JSONObject perform(String action, JSONObject params) throws IOException, ConduitAPIException {
    if (action == "harbormaster.sendmessage") {
      JSONObject json = (JSONObject) ((JSONArray) params.get("lint")).get(0);
      JSONObject parsed = result.toHarbormaster();
      assertNotNull(parsed);
      assertNotNull(json);
      for (String key : (Set<String>) params.keySet()) {
        assertEquals("mismatch in expected json key: " + key, parsed.get(key), json.get(key));
      }
      return result.toHarbormaster();
    }
    return new JSONObject();
  }
};

相关文章