|
|||||||||
前のクラス 次のクラス | フレームあり フレームなし | ||||||||
概要: 入れ子 | フィールド | コンストラクタ | メソッド | 詳細: フィールド | コンストラクタ | メソッド |
java.lang.Objectnet.arnx.jsonic.JSON
public class JSON
The JSONIC JSON class provides JSON encoding and decoding as defined by RFC 4627.
The following example illustrates how to encode and decode. The code:
// encodes a object into a json string. String s = JSON.encode(o); // decodes a json string into a object. Object o = JSON.decode(s); // decodes a json string into a typed object. Foo foo = JSON.decode(s, Foo.class);
Advanced topic:
// formats a object into a json string with indents for debug. JSON json = new JSON(); json.setPrettyPrint(true); String pretty = json.format(o); // invokes method by a json array. JSON json = new JSON(); Object result = json.invoke(data, "method", "[true, 1]");
java type | json type |
---|---|
java.util.Map | object |
java.lang.Serializable (public property or field) | |
java.lang.Object[] | array |
java.util.Collection | |
boolean[], short[], int[], long[], float[], double[] | |
java.lang.CharSequence | string |
char[] | |
java.lang.Character | |
char | |
byte[] | string (base64) |
java.util.Locale | string (language-country) |
java.lang.Number | number |
byte, short, int, long, float, double | |
java.util.Date | number (milliseconds since 1970) |
java.util.Calendar | |
java.lang.Boolean | true/false |
boolean | |
null | null |
json type | java type |
---|---|
object | java.util.HashMap |
array | java.util.ArrayList |
string | java.lang.String |
number | java.math.BigDecimal |
true/false | java.lang.Boolean |
null | null |
コンストラクタの概要 | |
---|---|
JSON()
|
メソッドの概要 | ||
---|---|---|
protected java.lang.Object |
convert(java.lang.Package pk,
java.lang.Object value,
java.lang.Class c,
java.lang.reflect.Type type)
|
|
protected java.lang.Object |
create(java.lang.Class<?> c)
|
|
static java.lang.Object |
decode(java.lang.String source)
Decodes a json string into a object. |
|
static
|
decode(java.lang.String source,
java.lang.Class<? extends T> c)
Decodes a json string into a typed object. |
|
static java.lang.String |
encode(java.lang.Object source)
Encodes a object into a json string. |
|
static java.lang.String |
encode(java.lang.Object source,
boolean prettyPrint)
Encodes a object into a json string. |
|
java.lang.String |
format(java.lang.Object source)
|
|
java.lang.StringBuilder |
format(java.lang.Object source,
java.lang.StringBuilder sb)
|
|
protected void |
handleConvertError(java.lang.String key,
java.lang.Object value,
java.lang.Class c,
java.lang.reflect.Type type,
java.lang.Exception e)
|
|
protected void |
handleParseError(java.lang.String message,
java.lang.CharSequence s,
int pos,
int line,
int col)
|
|
java.lang.Object |
invoke(java.lang.Object o,
java.lang.String methodName,
java.lang.CharSequence json)
Invokes the targeted method for the specified object, with the specified json parameters. |
|
protected boolean |
limit(java.lang.reflect.Method method)
|
|
java.lang.Object |
parse(java.lang.CharSequence source)
|
|
|
parse(java.lang.CharSequence source,
java.lang.Class<? extends T> c)
|
|
void |
setExtendedMode(boolean value)
Sets extended mode. |
|
void |
setMaxDepth(int value)
Sets maximum depth for the nest level. |
|
void |
setPrettyPrint(boolean value)
Output json string is to human-readable format. |
クラス java.lang.Object から継承されたメソッド |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
コンストラクタの詳細 |
---|
public JSON()
メソッドの詳細 |
---|
public void setPrettyPrint(boolean value)
value
- true to format human-readable, false to shorten.public void setMaxDepth(int value)
value
- maximum depth for the nest level.public void setExtendedMode(boolean value)
value
- true to enable extension mode, false to disablepublic static java.lang.String encode(java.lang.Object source)
source
- a object to encode.
public static java.lang.String encode(java.lang.Object source, boolean prettyPrint)
source
- a object to encode.prettyPrint
- output a json string with indent, space or break.
public static java.lang.Object decode(java.lang.String source) throws java.text.ParseException
source
- a json string to decode
java.text.ParseException
- if the beginning of the specified string cannot be parsed.public static <T> T decode(java.lang.String source, java.lang.Class<? extends T> c) throws java.lang.Exception
source
- a json string to decodec
- class for converting
java.text.ParseException
- if the beginning of the specified string cannot be parsed.
java.lang.Exception
public java.lang.String format(java.lang.Object source)
public java.lang.StringBuilder format(java.lang.Object source, java.lang.StringBuilder sb)
public java.lang.Object parse(java.lang.CharSequence source) throws java.text.ParseException
java.text.ParseException
public <T> T parse(java.lang.CharSequence source, java.lang.Class<? extends T> c) throws java.lang.Exception
java.lang.Exception
public java.lang.Object invoke(java.lang.Object o, java.lang.String methodName, java.lang.CharSequence json) throws java.lang.Exception
o
- the object the underlying method is invoked frommethodName
- the invoked method namejson
- the parameters used for the method call. json should be array, or appended '[' and ']'.
java.lang.Exception
protected void handleParseError(java.lang.String message, java.lang.CharSequence s, int pos, int line, int col) throws java.text.ParseException
java.text.ParseException
protected java.lang.Object convert(java.lang.Package pk, java.lang.Object value, java.lang.Class c, java.lang.reflect.Type type) throws java.lang.Exception
java.lang.Exception
protected void handleConvertError(java.lang.String key, java.lang.Object value, java.lang.Class c, java.lang.reflect.Type type, java.lang.Exception e) throws java.lang.Exception
java.lang.Exception
protected java.lang.Object create(java.lang.Class<?> c) throws java.lang.Exception
java.lang.Exception
protected boolean limit(java.lang.reflect.Method method)
|
|||||||||
前のクラス 次のクラス | フレームあり フレームなし | ||||||||
概要: 入れ子 | フィールド | コンストラクタ | メソッド | 詳細: フィールド | コンストラクタ | メソッド |