JSONにおけるget()とopt()の違い


get()の値が正しくないと異常が投げ出され、try catchまたはthrowで包む必要があります
opt()の値が正しくないと変換やフレンドリー値の出力を試み、異常を投げ出さない
opt
public java.lang.Object opt(java.lang.String key)

Get an optional value associated with a key.
 
Parameters: key - A key string.
Returns:
An object which is the value, or null if there is no value.
 
optDouble
public double optDouble(java.lang.String key)

Get an optional double associated with a key, or NaN if there is no such key or if its value is not a number. If the value is a string, an attempt will be made to evaluate it as a number.
optBoolean
public boolean optBoolean(java.lang.String key)

Get an optional boolean associated with a key. It returns false if there is no such key, or if the value is not
optInt
public int optInt(java.lang.String key)

Get an optional int value associated with a key, or zero if there is no such key or if the value is not a number. If the value is a string, an attempt will be made to evaluate it as a number.