Package net.minidev.json
Class JSONNavi<T>
- java.lang.Object
-
- net.minidev.json.JSONNavi<T>
-
public class JSONNavi<T> extends Object
A JQuery like Json editor, accessor.- Since:
- 1.0.9
- Author:
- Uriel Chemouni <[email protected]>
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description JSONNavi<T>
add(Object... values)
add value to the current arraysJSONNavi<T>
array()
Set current value as Json Array You can also skip this call Arrays can be create automatically.boolean
asBoolean()
get the current value as boolean if the current Object is null or is not a boolean return falseBoolean
asBooleanObj()
get the current object value as Boolean if the current Object is not a Boolean return null.double
asDouble()
get the current value as double if the current Object is null return Double.NaNDouble
asDoubleObj()
get the current object value as Double if the current Double can not be cast as Integer return null.float
asFloat()
get the current value as float if the current Object is null return Float.NaNFloat
asFloatObj()
get the current object value as Float if the current Float can not be cast as Integer return null.int
asInt()
get the current value as int if the current Object is null return 0Integer
asIntegerObj()
get the current object value as Integer if the current Object can not be cast as Integer return null.long
asLong()
get the current value as long if the current Object is null return 0Long
asLongObj()
get the current object value as Long if the current Object can not be cast as Long return null.String
asString()
get the current object value as String if the current Object is null return null.JSONNavi<?>
at(int index)
Access to the index position.JSONNavi<?>
at(String key)
JSONNavi<?>
atNext()
Access to last + 1 the index position.Object
get(int index)
Object
get(String key)
Object
getCurrentObject()
double
getDouble(String key)
int
getInt(String key)
Integer
getInteger(String key)
String
getJPath()
Collection<String>
getKeys()
T
getRoot()
int
getSize()
String
getString(String key)
boolean
hasFailure()
boolean
hasKey(String key)
boolean
isArray()
is the current node is an arrayboolean
isObject()
is the current node is an objectstatic JSONNavi<JSONAwareEx>
newInstance()
static JSONNavi<JSONArray>
newInstanceArray()
static JSONNavi<JSONObject>
newInstanceObject()
JSONNavi<T>
object()
Set current value as Json Object You can also skip this call, Objects can be create automatically.JSONNavi<T>
root()
return to root nodeJSONNavi<T>
set(Boolean bool)
set current value as BooleanJSONNavi<T>
set(Number num)
set current value as NumberJSONNavi<T>
set(String text)
set current value as StringJSONNavi<T>
set(String key, double value)
write an value in the current objectJSONNavi<T>
set(String key, float value)
write an value in the current objectJSONNavi<T>
set(String key, int value)
write an value in the current objectJSONNavi<T>
set(String key, long value)
write an value in the current objectJSONNavi<T>
set(String key, Number value)
JSONNavi<T>
set(String key, String value)
String
toString()
return the Object as a Json StringString
toString(JSONStyle compression)
return the Object as a Json StringJSONNavi<?>
up()
Move one level up in Json tree.JSONNavi<?>
up(int level)
call up() level times.
-
-
-
Constructor Detail
-
JSONNavi
public JSONNavi(JsonReaderI<? super T> mapper)
-
JSONNavi
public JSONNavi(String json)
-
JSONNavi
public JSONNavi(String json, JsonReaderI<T> mapper)
-
-
Method Detail
-
newInstance
public static JSONNavi<JSONAwareEx> newInstance()
-
newInstanceObject
public static JSONNavi<JSONObject> newInstanceObject()
-
hasFailure
public boolean hasFailure()
-
getCurrentObject
public Object getCurrentObject()
-
getKeys
public Collection<String> getKeys()
-
getSize
public int getSize()
-
getInt
public int getInt(String key)
-
getDouble
public double getDouble(String key)
-
hasKey
public boolean hasKey(String key)
-
get
public Object get(int index)
-
set
public JSONNavi<T> set(String key, long value)
write an value in the current object- Parameters:
key
- key to accessvalue
- new value- Returns:
- this
-
set
public JSONNavi<T> set(String key, int value)
write an value in the current object- Parameters:
key
- key to accessvalue
- new value- Returns:
- this
-
set
public JSONNavi<T> set(String key, double value)
write an value in the current object- Parameters:
key
- key to accessvalue
- new value- Returns:
- this
-
set
public JSONNavi<T> set(String key, float value)
write an value in the current object- Parameters:
key
- key to accessvalue
- new value- Returns:
- this
-
add
public JSONNavi<T> add(Object... values)
add value to the current arrays- Parameters:
values
- to add- Returns:
- this
-
asString
public String asString()
get the current object value as String if the current Object is null return null.- Returns:
- value as string
-
asDouble
public double asDouble()
get the current value as double if the current Object is null return Double.NaN- Returns:
- value as double
-
asDoubleObj
public Double asDoubleObj()
get the current object value as Double if the current Double can not be cast as Integer return null.- Returns:
- value as Double
-
asFloat
public float asFloat()
get the current value as float if the current Object is null return Float.NaN- Returns:
- value as float
-
asFloatObj
public Float asFloatObj()
get the current object value as Float if the current Float can not be cast as Integer return null.
-
asInt
public int asInt()
get the current value as int if the current Object is null return 0- Returns:
- value as Int
-
asIntegerObj
public Integer asIntegerObj()
get the current object value as Integer if the current Object can not be cast as Integer return null.- Returns:
- the current node value as an Integer
-
asLong
public long asLong()
get the current value as long if the current Object is null return 0- Returns:
- value as long
-
asLongObj
public Long asLongObj()
get the current object value as Long if the current Object can not be cast as Long return null.- Returns:
- value as Long
-
asBoolean
public boolean asBoolean()
get the current value as boolean if the current Object is null or is not a boolean return false- Returns:
- boolean
-
asBooleanObj
public Boolean asBooleanObj()
get the current object value as Boolean if the current Object is not a Boolean return null.- Returns:
- Boolean object
-
object
public JSONNavi<T> object()
Set current value as Json Object You can also skip this call, Objects can be create automatically.- Returns:
- the current node as an object
-
array
public JSONNavi<T> array()
Set current value as Json Array You can also skip this call Arrays can be create automatically.- Returns:
- the current node as an array
-
set
public JSONNavi<T> set(Number num)
set current value as Number- Parameters:
num
- new value for the current node- Returns:
- this for code chaining
-
set
public JSONNavi<T> set(Boolean bool)
set current value as Boolean- Parameters:
num
- new value for the current node- Returns:
- this for code chaining
-
set
public JSONNavi<T> set(String text)
set current value as String- Parameters:
text
- text value- Returns:
- this for code chaining
-
getRoot
public T getRoot()
-
isArray
public boolean isArray()
is the current node is an array- Returns:
- true if the current node is an array
-
isObject
public boolean isObject()
is the current node is an object- Returns:
- true if the current node is an object
-
at
public JSONNavi<?> at(int index)
Access to the index position. If index is less than 0 access element index from the end like in python.- Parameters:
index
- 0 based desired position in Array
-
atNext
public JSONNavi<?> atNext()
Access to last + 1 the index position. this method can only be used in writing mode.
-
up
public JSONNavi<?> up(int level)
call up() level times.- Parameters:
level
- number of parent move.
-
up
public JSONNavi<?> up()
Move one level up in Json tree. if no more level up is available the statement had no effect.
-
toString
public String toString()
return the Object as a Json String
-
toString
public String toString(JSONStyle compression)
return the Object as a Json String- Parameters:
compression
-
-
getJPath
public String getJPath()
- Returns:
- JPath to the current position
-
-