Parse JSON () はエラーを適切に処理しないため、使いにくいです。RunProgram やボタンからのコールバックでは、失敗を通知する不要なモデル ダイアログが作成されます。ログでも失敗が通知されます。これを修正するには、追加の JSL が必要です。
New Window( "parsejson",
Button Box( "parse",
local( {birestore, errText},
birestore = Batch Interactive( 1 ); // makes an alert dialog from a button without this
errText = Log Capture( p = Parse JSON( "\!n" /* invalid json error */ ) ); // writes to the log without this
Batch Interactive( birestore ); // pop the previous behavior
If( Length( errText ), Throw( "Caught an error:" || char(errText) ) ); // handle unexpected error, somehow
/* use p here */
)
)
);
提案: 動作を変更するには、parseJson(x, throwIfError() ) のようなオプションのパラメータを追加します。
フェイルセーフなJSON解析