JsonObject (クラス)
public JsonObject {inherits {HashTable-of String, JsonValue}}
パッケージ: CURL.IO.JSON

値が設定された順に保存される StringJsonValue のテーブルです。

説明

値が設定された順番でキーや値を反復します。

注意事項

JsonValue-parseJsonValue-writeJsonValue-to-String も参照してください。
導入: バージョン 6.0

コンストラクタ
clone-from:JsonObject を初期化します。
コンストラクタ public {JsonObject.clone-from from:JsonObject}
default:JsonObject を初期化します。
コンストラクタ public {JsonObject.default efficient-size:int = 4, ...:any}

プロパティ
プロパティ 継承 HashTable-of: efficient-size, size
プロパティ 継承 Association-of: empty?, key-type
プロパティ 継承 Aggregate-of: element-type

メソッド
clear:すべての要素を削除します。
public {JsonObject.clear}:void
clone:ハッシュ テーブルのクローンを返します。
public {JsonObject.clone}:JsonObject
get-by-index:index 番目のアイテムとして追加された値を返します。
public {JsonObject.get-by-index
index:int
}:(key:String, value:JsonValue)
get-by-index-if-exists:index 番目のアイテムとして追加された値を返します。
public {JsonObject.get-by-index-if-exists
index:int
}:(key:String, value:JsonValue, found?:bool)
keys-to-Iterator:コレクションの各キーを含む Iterator-of を返します。
public {JsonObject.keys-to-Iterator}:{Iterator-of String}
rehash:self を再ハッシュします。
public {JsonObject.rehash}:void
remove:要素を削除します。
public {JsonObject.remove
key:String,
length:int = 1,
error-if-missing?:bool = true
}:void
set:要素の値を設定します。
public {JsonObject.set key:String, element:JsonValue}:void
to-Iterator:self の要素を生成する Iterator-of を返します。
public {JsonObject.to-Iterator}:{Iterator-of JsonValue}
メソッド 継承 HashTable-of: filter-clone, filter-keys-clone, get-if-exists, get-key-if-exists, grow, key-exists?, object-serialize
メソッド 継承 Association-of: filter, filter-keys, get, get-key
メソッド 継承 Object: object-describe, object-describe-for-debugging



コンストラクタ詳細
clone-from (コンストラクタ)
public {JsonObject.clone-from from:JsonObject}

JsonObject を初期化します。

from: self の初期の内容は from からコピーされます。
導入: バージョン 6.0


default (コンストラクタ)
public {JsonObject.default efficient-size:int = 4, ...:any}

JsonObject を初期化します。

説明

HashTable-of.default を参照してください。
導入: バージョン 6.0



プロパティ詳細


メソッド詳細
clear (メソッド)
public {JsonObject.clear}:void

すべての要素を削除します。


{value
    || Declare and initialize a hash table with
    || int keys and String elements.
    let my-table:{HashTable-of int, String} =
        {new {HashTable-of int, String},
             162094, "tom",
             439853, "dick",
             098627, "harry"
        }

    || Clear the hash table.
    {my-table.clear}

    || Check if the hash table is empty.
    {text The assertion that the hash table is empty is...
        {value my-table.empty?}}
}


clone (メソッド)
public {JsonObject.clone}:JsonObject

ハッシュ テーブルのクローンを返します。

戻り値

HashTable-of のインスタンス。オブジェクトは、self と同じデータ型およびデータを持ちます。

説明

クローンは、self と同じデータ型を持つ新しいオブジェクトです。クローンは、self の浅いコピー(shallow copy)です。つまり、クローンには self の元の要素への固有の参照が含まれます。したがって、元のコレクション内の要素を置換または削除しても、クローン コレクション内の要素には影響しません。


|| Declare and initialize a hash table with
|| String keys and int elements.
{let table-1:{HashTable-of int, String} =
    {new {HashTable-of int, String},
         162094, "tom",
         439853, "dick",
         098627, "harry"
    }
}

|| Declare table-2 (a target hash table) and initialize it with
|| a copy of the contents of table-1.
{let table-2:{HashTable-of int, String} = {table-1.clone}}

|| Use a VBox to display the contents of table-2.
|| For each key in table-2 add an HBox to the VBox.
|| The HBox contains the relevant key and element.
|| Then display the VBox.
{let message:VBox = {VBox}}
{for key i:int in table-2 do
    {message.add {HBox i, " ", {table-2.get i}}}
}
{value message}

注意事項

クローンの詳細については、『Curl 開発者ガイド』の「コレクション:ハッシュ テーブル」でクローンに関するセクションを参照してください。


get-by-index (メソッド)
public {JsonObject.get-by-index
index:int
}:(key:String, value:JsonValue)

index 番目のアイテムとして追加された値を返します。

index: 何番目のアイテムを取得するかを示します。

戻り値

index 番目のアイテムとして追加されたキーと値になります。indexが範囲外の場合、ArrayBoundsException がスローされます。
導入: バージョン 6.0


get-by-index-if-exists (メソッド)
public {JsonObject.get-by-index-if-exists
index:int
}:(key:String, value:JsonValue, found?:bool)

index 番目のアイテムとして追加された値を返します。

index: 何番目のアイテムを取得するかを示します。

戻り値

index 番目のアイテムとして追加されたキーと値になります。又、index が範囲内にある場合、true そうでなければ found?false になります。
導入: バージョン 6.0


keys-to-Iterator (メソッド)
public {JsonObject.keys-to-Iterator}:{Iterator-of String}

コレクションの各キーを含む Iterator-of を返します。

戻り値

self の要素と同じパラメータ化データ型を持つ Iterator-of。つまり、self{Association-of int, String} の場合、このメソッドは {Iterator-of int} を返します。

説明

Iterator-of のキーの順序は、任意に指定できます (Association-of のインスタンスが、順序付けられたコレクションでない場合もあるからです)。


{value
    || Declare and initialize a hash table with
    || int keys and String elements.
    let my-table:{HashTable-of int, String} =
        {new {HashTable-of int, String},
             162094, "tom",
             439853, "dick",
             098627, "harry"
        }

    || Create an Iterator-of from the set.
    let my-iterator:{Iterator-of int} =
        {my-table.keys-to-Iterator}

    || Use a VBox to display the contents of my-iterator.
    || Iterate over the contents of my-iterator, adding
    || them to the VBox.  Then display the VBox.
    let message:VBox = {VBox}
    {for each-element:int in my-iterator do
        {message.add each-element}
    }
    message

    || Note that the order of the elements in a hash
    || table is arbitrary.
}

注意事項

for コンテナ ループを使って同じ結果を得ることもできます。ただし、この反復処理メカニズムをオーバーライドすると、予期外の結果が生じる可能性があるので、可能な限り for ループを使用してください。

注意事項

これは Association-of の抽象メソッドで、Association-of のサブクラス内で実装されます。


rehash (メソッド)
public {JsonObject.rehash}:void

self を再ハッシュします。



remove (メソッド)
public {JsonObject.remove
key:String,
length:int = 1,
error-if-missing?:bool = true
}:void

要素を削除します。

key: 削除する要素のキーの値。この値は、self のキーと同じデータ型を持つ必要があります。
length: このパラメータを指定するとエラーになります。

length コレクションから削除する連続する要素の数を示す int。ただし、このメソッドでは、ハッシュ テーブルは順序付けられたコレクションではないので、このパラメータには意味がありません。このパラメータは、順序付けられたコレクションを実装する Sequence-of のサブクラスにのみ適用されます。

このメソッドでは、length は既定値の 1 に設定されています。
error-if-missing?: ユーザーが存在しない要素を削除しようとしたときにこのメソッドがエラーを生成するかどうかを示すブール値のフラグ。error-if-missing?true に設定した場合、存在しない要素を削除しようとするとエラーがスローされます。エラーが発生するとプログラムの実行が停止し、エラー メッセージが表示されます。既定では、error-if-missing?true です。error-if-missing?false の場合、このメソッドはエラーを生成しません。error-if-missing? キーワード引数。error-if-missing?を指定するには、メソッド呼び出し内のキーワードに必要な値 (例:error-if-missing?=false) を指定します。

説明

{self.key-exists? key}true を返す場合、このメソッドは self から適切なキーおよび要素を削除します。

{self.key-exists? key}false で、 error-if-missing?true の場合、このメソッドはエラーをスローします。ただし、 error-if-missing?false の場合、このメソッドは何のアクションも実行しません。


{value
    || Declare and initialize a hash table with
    || String keys and int elements.
    let price:{HashTable-of String, int} =
        {new {HashTable-of String, int},
             "apple", 56,
             "banana", 87,
             "cherry", 34
        }

    || Remove the element at key "banana".
    {price.remove "banana"}

    || Use a VBox to display the contents of price.
    || For each key in price, add a string to the VBox.
    || The string contains the relevant key and element.
    || Then display the VBox.
    let message:VBox = {VBox}
    {for key each-element:String in price do
        {message.add each-element & " " & {price.get each-element}}
    }
    message

    || Note that the order of the elements in a hash
    || table is arbitrary.
}

注意事項

これは Association-of の抽象メソッドで、Association-of のサブクラス内で実装されます。


set (メソッド)
public {JsonObject.set key:String, element:JsonValue}:void

要素の値を設定します。

key: 設定する要素のキーの値。この値は、self のキーと同じデータ型を持つ必要があります。
element: 要素の値。この値は、selfの要素と同じデータ型を持つ必要があります。

説明

keyself に存在する場合、このメソッドは element に関連付けられた要素の値を変更します。keyself に存在しない場合、このメソッドは新しい要素 (keyelement) を self に追加します。


{value
    || Declare and initialize a hash table with
    || String keys and int elements.
    let price:{HashTable-of String, int} =
        {new {HashTable-of String, int},
             "apple", 56,
             "banana", 87,
             "cherry", 34
        }

    || Change the element at key "banana".
    {price.set "banana", 72}

    || Add an element for "pear".
    {price.set "pear", 62}

    || Use a VBox to display the contents of price.
    || For each key in price, add a string to the VBox.
    || The string contains the relevant key and element.
    || Then display the VBox.
    let message:VBox = {VBox}
    {for key each-element:String in price do
        {message.add each-element & " " & {price.get each-element}}
    }
    message

    || Note that the order of the elements in a hash
    || table is arbitrary.
}

注意事項

これは Association-of の抽象メソッドで、Association-of のサブクラス内で実装されます。


to-Iterator (メソッド)
public {JsonObject.to-Iterator}:{Iterator-of JsonValue}

self の要素を生成する Iterator-of を返します。

戻り値

self の要素と同じパラメータ化データ型を持つ Iterator-of。つまり、self{HashTable-of int, String } の場合、このメソッドは {{Iterator-of String}} を返します。


{value                || Declare and initialize a hash table with
    || String keys and int elements
    let h:{HashTable-of int, String} =
        {new {HashTable-of int, String},
             162094, "tom",
             439853, "dick",
             098627, "harry"
        }

    || Create an Iterator-of from the hash table.
    let my-iterator:{Iterator-of String} =
        {h.to-Iterator}

    || Use a VBox to display the contents of my-iterator.
    || Iterate over the contents of my-iterator, adding
    || them to the VBox.  Then display the VBox.
    let message:VBox = {VBox}
    {for each-element:String in my-iterator do
        {message.add each-element}
    }
    message
}

注意事項

ハッシュ テーブルは、順序付けられていないコレクションなので、Iterator-of 内の要素の順序は任意に指定できます。

注意事項

forコンテナ ループを使用しても同じ結果を得ることができます。ただし、この反復処理メカニズムをオーバーライドすると、予想外の結果が生じる場合があるので、実際にはコンテナの反復には for を使用することをお勧めします。