org.apache.tapestry5.json.JSONArray类的使用及代码示例

x33g5p2x  于2022-01-22 转载在 其他  
字(7.9k)|赞(0)|评价(0)|浏览(121)

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

JSONArray介绍

[英]A dense indexed sequence of values. Values may be any mix of JSONObject, other JSONArray, Strings, Booleans, Integers, Longs, Doubles, null or JSONObject#NULL. Values may not be Double#isNaN(), Double#isInfinite(), or of any type not listed here. JSONArray has the same type coercion behavior and optional/mandatory accessors as JSONObject. See that class' documentation for details. Warning: this class represents null in two incompatible ways: the standard Java null reference, and the sentinel value JSONObject#NULL. In particular, get fails if the requested index holds the null reference, but succeeds if it holds JSONObject.NULL. Instances of this class are not thread safe.
[中]密集的索引值序列。值可以是JSONObject、其他JSONArray、字符串、布尔值、整数、long值、double值、null值或JSONObject#null值的任意组合。值不能是Double#isNaN()、Double#isInfinite(),也不能是此处未列出的任何类型。JSONArray与JSONObject具有相同的类型强制行为和可选/强制访问器。有关详细信息,请参阅该类的文档。警告:此类以两种不兼容的方式表示null:标准Java null引用和sentinel值JSONObject#null。特别是,如果请求的索引包含null引用,get将失败,但如果它包含JSONObject,get将成功。无效的此类的实例不是线程安全的。

代码示例

代码示例来源:origin: json-path/JsonPath

@Override
public Object createArray() {
 return new JSONArray();
}

代码示例来源:origin: json-path/JsonPath

@Override
public void setArrayIndex(final Object array, final int index, final Object newValue) {
 Object v = newValue == null ? JSONObject.NULL : newValue;
 JSONArray list = (JSONArray) array;
 list.put(index, v);
}

代码示例来源:origin: json-path/JsonPath

@Override
public int length(final Object obj) {
 if (obj instanceof JSONArray) {
  return ((JSONArray) obj).length();
 } else if (obj instanceof JSONObject) {
  return ((JSONObject) obj).length();
 } else {
  throw new IllegalArgumentException("Cannot determine length of " + obj + ", unsupported type.");
 }
}

代码示例来源:origin: org.got5/tapestry5-jquery

/**
   * Transforms the matches into a JSONArray
   *
   * @return JSONArray of available responses
   */
  protected JSONArray generateResponseJSON(List matches)
  {
    JSONArray array = new JSONArray();
    for (Object o : matches)
    {
      if (o instanceof JSONObject) array.put(o);
      else array.put(o.toString());
    }
    return array;
  }
}

代码示例来源:origin: apache/tapestry-5

public void addInitialization(InitializationPriority priority, String moduleName, String functionName, JSONArray arguments)
{
  assert priority != null;
  assert InternalUtils.isNonBlank(moduleName);
  String name = functionName == null ? moduleName : moduleName + ":" + functionName;
  if ((arguments == null || arguments.length() == 0))
  {
    if (pureInits.contains(name))
    {
      // A degenerate case is a pure init added repeatedly with different priorities. That isn't handled:
      // the first priority wins.
      return;
    }
    pureInits.add(name);
    InternalUtils.addToMapList(inits, priority, name);
  } else
  {
    JSONArray init = new JSONArray();
    init.put(name);
    init.putAll(arguments);
    InternalUtils.addToMapList(inits, priority, init);
  }
  initCount++;
}

代码示例来源:origin: apache/tapestry-5

private void addPublishEventInfo(Flow<EventHandlerMethod> eventHandlerMethods,
    MutableComponentModel model)
{
  JSONArray publishEvents = new JSONArray();
  for (EventHandlerMethod eventHandlerMethod : eventHandlerMethods)
  {
    if (eventHandlerMethod.publishEvent != null)
    {
      publishEvents.put(eventHandlerMethod.eventType.toLowerCase());
    }
  }
  
  // If we do have events to publish, we apply the mixin and pass
  // event information to it.
  if (publishEvents.length() > 0) {
    model.addMixinClassName(PublishServerSideEvents.class.getName(), "after:*");
    model.setMeta(InternalConstants.PUBLISH_COMPONENT_EVENTS_META, publishEvents.toString());
  }
}

代码示例来源:origin: apache/tapestry-5

@Override
protected void processSubmission(String controlName)
{
  String parameterValue = request.getParameter(controlName);
  JSONArray values = new JSONArray(parameterValue);
  // Use a couple of local variables to cut down on access via bindings
  Collection<Object> selected = this.selected;
  selected.clear();
  ValueEncoder encoder = this.encoder;
  // TODO: Validation error if the model does not contain a value.
  int count = values.length();
  for (int i = 0; i < count; i++)
  {
    String value = values.getString(i);
    Object objectValue = encoder.toValue(value);
    selected.add(objectValue);
  }
  putPropertyNameIntoBeanValidationContext("selected");
  try
  {
    fieldValidationSupport.validate(selected, resources, validate);
    this.selected = selected;
  } catch (final ValidationException e)
  {
    validationTracker.recordError(this, e.getMessage());
  }
  removePropertyNameFromBeanValidationContext();
}

代码示例来源:origin: apache/tapestry-5

public String getInitialJSON()
{
  JSONArray array = new JSONArray();
  for (Object o : selected)
  {
    String value = encoder.toClient(o);
    array.put(value);
  }
  return array.toString(compactJSON);
}

代码示例来源:origin: apache/tapestry-5

array.checkedPut(value);
} else {
  JSONArray array = new JSONArray();
  array.checkedPut(current);
  array.checkedPut(value);
  nameValuePairs.put(name, array);

代码示例来源:origin: json-path/JsonPath

@Override
public Object getArrayIndex(final Object obj, final int idx) {
 return ((JSONArray) obj).get(idx);
}

代码示例来源:origin: apache/tapestry-5

private String convert(List<?> input)
{
  return new JSONArray().putAll(input).toString(compactJSON);
}

代码示例来源:origin: apache/tapestry-5

private boolean selected(String clientId, String elementName)
{
  // Case #1: via JavaScript, the client id is passed up.
  String raw = request.getParameter(Form.SUBMITTING_ELEMENT_ID);
  if (InternalUtils.isNonBlank(raw) &&
      new JSONArray(raw).getString(0).equals(clientId))
  {
    return true;
  }
  // Case #2: No JavaScript, look for normal semantic (non-null value for the element's name).
  // If configured as an image submit, look for a value for the x position. Ah, the ugliness
  // of HTML.
  String name = image == null ? elementName : elementName + ".x";
  String value = request.getParameter(name);
  return value != null;
}

代码示例来源:origin: org.apache.tapestry/tapestry-json

/**
 * Create a new array, and adds all values fro the iterable to the array (using {@link #putAll(Iterable)}.
 *
 * This is implemented as a static method so as not to break the semantics of the existing {@link #JSONArray(Object...)} constructor.
 * Adding a constructor of type Iterable would change the meaning of <code>new JSONArray(new JSONArray())</code>.
 *
 * @param iterable
 *         collection ot value to include, or null
 * @since 5.4
 */
public static JSONArray from(Iterable<?> iterable)
{
  return new JSONArray().putAll(iterable);
}

代码示例来源:origin: apache/tapestry-5

/**
   * Commits changes, adding one or more keys to the reply.
   *
   * @param reply
   *         JSON Object to be sent to client
   */
  public void commit(JSONObject reply)
  {
    if (libraryURLs.length() > 0)
    {
      reply.in(InternalConstants.PARTIAL_KEY).put("libraries", libraryURLs);
    }

    if (stylesheets.length() > 0)
    {
      reply.in(InternalConstants.PARTIAL_KEY).put("stylesheets", stylesheets);
    }

    List<?> inits = initsManager.getSortedInits();

    if (inits.size() > 0)
    {
      reply.in(InternalConstants.PARTIAL_KEY).put("inits", JSONArray.from(inits));
    }
  }
}

代码示例来源:origin: apache/tapestry-5

public void addInitializerCall(InitializationPriority priority, String functionName,
                JSONArray parameter)
{
  // TAP5-2300: In 5.3, a JSONArray implied an array of method arguments, so unwrap and add
  // functionName to the arguments
  List parameterList = new ArrayList(parameter.length() + 1);
  parameterList.add(functionName);
  parameterList.addAll(parameter.toList());
  createInitializer(priority).with(parameterList.toArray());
}

代码示例来源:origin: org.apache.tapestry/tapestry-json

/**
 * Returns an array containing the string names in this object. This method
 * returns null if this object contains no mappings.
 *
 * @return the names.
 */
public JSONArray names() {
  return nameValuePairs.isEmpty()
      ? null
      : JSONArray.from(nameValuePairs.keySet());
}

代码示例来源:origin: apache/tapestry-5

public void processResultValue(JSONArray value) throws IOException
  {
    PrintWriter pw = response.getPrintWriter(contentType.toString());

    value.print(pw, compactJSON);

    pw.close();
  }
}

代码示例来源:origin: apache/tapestry-5

public void addScript(InitializationPriority priority, String script)
{
  addInitialization(priority, "t5/core/pageinit", "evalJavaScript", new JSONArray().put(script));
}

代码示例来源:origin: org.got5/tapestry5-jquery

JSONArray values = new JSONArray(parameterValue);
int count = values.length();
for (int i = 0; i < count; i++)
  String value = values.getString(i);

代码示例来源:origin: org.apache.tapestry/tapestry-json

array.checkedPut(value);
} else {
  JSONArray array = new JSONArray();
  array.checkedPut(current);
  array.checkedPut(value);
  nameValuePairs.put(name, array);

相关文章