类 JsonTool
java.lang.Object
org.apache.velocity.tools.generic.SafeConfig
org.apache.velocity.tools.generic.ImportSupport
org.apache.velocity.tools.generic.JsonTool
- 所有已实现的接口:
Serializable,Iterable
@DefaultKey("json")
@InvalidScope("session")
public class JsonTool
extends ImportSupport
implements Iterable, Serializable
Tool which can parse a JSON file.
Usage:
- $json.parse(JSON string)
- $json.read(file or classpath resource)
- $json.fetch(URL)
Configuration parameters:
resource=file or classpath resourcesource=URL
Example configuration:
<tools>
<toolbox scope="request">
<tool class="org.apache.velocity.tools.generic.JsonTool"
key="foo" resource="doc.xml"/>
</toolbox>
</tools>
- 从以下版本开始:
- VelocityTools 3.0
- 版本:
- $Id:$
- 作者:
- Claude Brisson
- 另请参阅:
-
嵌套类概要
从类继承的嵌套类/接口 org.apache.velocity.tools.generic.ImportSupport
ImportSupport.SafeClosingHttpURLConnectionReader -
字段概要
字段从类继承的字段 org.apache.velocity.tools.generic.ImportSupport
RESOURCE_KEY, URL_KEY, VALID_SCHEME_CHARS从类继承的字段 org.apache.velocity.tools.generic.SafeConfig
LOCK_CONFIG_KEY, log, LOGGER_NAME_KEY, SAFE_MODE_KEY, USE_CLASS_LOGGER_KEY -
构造器概要
构造器 -
方法概要
修饰符和类型方法说明protected voidconfigure(ValueParser values) Looks for the "file" parameter and automatically usesinitJSON(String)to parse the file (searched in filesystem current path and classpath) and set the resulting JSON object as the root node for this instance.Reads and parses a remote or local URLget(int index) Get nth element from root json array.Get a property from root objectprotected voidinitializeImportSupport(ValueParser config) ImportSupport initializationprotected voidInitialize JSON content from a reader.protected voidInitialize JSON content from a string.iterator()Get an iterator.keys()Iterate keys of root object.keySet()Get set of root object keys.Reads and parses a local JSON resource fileroot()Get JSON root object.intsize()Get size of root object or array.toString()Convert JSON object or array into string从类继承的方法 org.apache.velocity.tools.generic.ImportSupport
acquireLocalURLReader, acquireLocalURLString, acquireReader, acquireRemoteURLReader, acquireRemoteURLString, acquireString, getClasspathResource, getContentTypeAttribute, getFileResource, getProtocol, getResourceReader, getResourceString, isRemoteURL, setSafeMode从类继承的方法 org.apache.velocity.tools.generic.SafeConfig
configure, getLog, initLogger, isConfigLocked, isSafeMode, setLockConfig从类继承的方法 java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait从接口继承的方法 java.lang.Iterable
forEach, spliterator
-
字段详细资料
-
importSupport
ImportSupport utility which provides underlying i/o
-
-
构造器详细资料
-
JsonTool
public JsonTool()
-
-
方法详细资料
-
initializeImportSupport
ImportSupport initialization- 参数:
config- configuration values
-
configure
Looks for the "file" parameter and automatically usesinitJSON(String)to parse the file (searched in filesystem current path and classpath) and set the resulting JSON object as the root node for this instance.- 覆盖:
configure在类中ImportSupport- 参数:
values- configuration values
-
initJSON
Initialize JSON content from a string.- 参数:
json- JSON string
-
initJSON
Initialize JSON content from a reader.- 参数:
reader- JSON stream reader
-
parse
- 参数:
json- JSON string- 返回:
- new JsonTool
-
read
Reads and parses a local JSON resource file- 参数:
resource- resource name- 返回:
- new JsonTool
-
fetch
Reads and parses a remote or local URL- 参数:
url- resource URL- 返回:
- new JSonTool
-
root
Get JSON root object.- 返回:
- root object or array
-
get
Get nth element from root json array.- 参数:
index- n- 返回:
- nth element, or null if root object is null or not an array
-
get
Get a property from root object- 参数:
key- property key- 返回:
- property value, or null
-
keys
Iterate keys of root object.- 返回:
- iterator
-
keySet
Get set of root object keys.- 返回:
- keys set
-
iterator
Get an iterator. For a root object, returns an iterator over key names. For a root array, returns an iterator over contained objects. -
size
public int size()Get size of root object or array.- 返回:
- size
-
toString
Convert JSON object or array into string
-