調査アンケート: Blockly のご利用体験についてお聞かせください
アンケートを開始
シリアル化
シリアル化は、ワークスペースの状態を保存して、後でワークスペースに再読み込みできるようにします。保存する必要があるデータをすべてテキストベースの形式に変換し、簡単に保存できます。
ワークスペースは JSON にシリアル化することをおすすめします。
詳細については、シリアル化をご覧ください。
保存
次のコード スニペットは、ワークスペースの状態を JSON に変換して保存する方法を示しています。
// Serialize the state.
const state = Blockly.serialization.workspaces.save(myWorkspace);
// Then you save the state, e.g. to local storage.
localStorage.setItem('workspace-state', state);
読み込み
次のコード スニペットは、保存した状態をワークスペースに読み込む方法を示しています。
// Get your saved state from somewhere, e.g. local storage.
const state = localStorage.getItem('workspace-state');
// Deserialize the state.
Blockly.serialization.workspaces.load(state, myWorkspace);
これにより、保存したブロック、変数、その他の要素がすべてワークスペースに作成されます。
特に記載のない限り、このページのコンテンツはクリエイティブ・コモンズの表示 4.0 ライセンスにより使用許諾されます。コードサンプルは Apache 2.0 ライセンスにより使用許諾されます。詳しくは、Google Developers サイトのポリシーをご覧ください。Java は Oracle および関連会社の登録商標です。
最終更新日 2024-11-04 UTC。
[null,null,["最終更新日 2024-11-04 UTC。"],[[["Serialization allows you to save the current state of your Blockly workspace (blocks, variables, etc.) into a text-based format, typically JSON, for later retrieval."],["You can save the serialized workspace data to a storage location like local storage and then load it back into a workspace to restore its previous state."],["Blockly provides APIs (`Blockly.serialization.workspaces.save` and `Blockly.serialization.workspaces.load`) for easily serializing and deserializing workspace states."]]],["Serialization saves workspace states for later loading by converting data into a text-based format, preferably JSON. To save, use `Blockly.serialization.workspaces.save(myWorkspace)` to get the state, then store it (e.g., in local storage). To load, retrieve the saved state and use `Blockly.serialization.workspaces.load(state, myWorkspace)` to recreate blocks, variables, and other elements in the workspace.\n"]]