JSON - Dans le champ d’application
L’include de script JSON fournit des méthodes incluses dans le champ d’application pour créer des objets JSON à partir d’une chaîne et pour transformer des objets JSON en chaînes.
Pour les applications incluses dans le périmètre, l’API JSON utilise des méthodes statiques qui appellent l’objet JSON natif JavaScript ES5.
Remarque :
Utilisez le mot clé global avec les appels de méthode JSON dans les scripts à portée, par exemple,
global. JSON.stringify(). Ne pas utiliser le mot clé global peut entraîner un message d’erreur, tel que ScopedRhinoObjectWrapper : not a wrappable type : com.glide.script.FieldGlideDescriptor.JSON dans le champ d’application : analyser (str chaîne)
Crée un type d’objet ou primitif à partir d’une chaîne au format JSON.
| Nom | Type | Description |
|---|---|---|
| str | Chaîne | Chaîne au format JSON. |
| Type | Description |
|---|---|
| Objet | Objet créé à partir de la chaîne spécifiée. |
var str = '{"name":"George","lastname":"Washington"}';
var obj = global.JSON.parse(str);
gs.info('The first name is ' + obj.name);
Sortie :
The first name is George
JSON dans le champ d’application : stringify(Object jsonObject)
Crée une chaîne à partir d’un objet JSON.
| Nom | Type | Description |
|---|---|---|
| objet jsonObjet | Objet | Objet JSON à transformer en chaîne. |
| Type | Description |
|---|---|
| Chaîne | Chaîne au format JSON. |
var obj = {"name":"George","lastname":"Washington"};
var str = global.JSON.stringify(obj);
gs.info('The object ' + str);
Sortie :
The object {"name":"George","lastname":"Washington"}