Analizza JSON () è difficile da usare perché non gestisce bene gli errori. In una callback, magari da RunProgram o da un pulsante, creerà una finestra di dialogo del modello indesiderata che annuncia l'errore. Annuncerà anche l'errore nel registro. Ci vuole JSL extra per risolverlo:
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 */
)
)
);
Suggerimento: aggiungi un parametro opzionale per modificare il comportamento, qualcosa come parseJson(x, throwIfError() )
Analisi JSON sicura