Helper XML in $util.xml - AWS AppSync GraphQL

Le traduzioni sono generate tramite traduzione automatica. In caso di conflitto tra il contenuto di una traduzione e la versione originale in Inglese, quest'ultima prevarrà.

Helper XML in $util.xml

Nota

Ora supportiamo principalmente il runtime APPSYNC_JS e la relativa documentazione. Prendi in considerazione l'utilizzo del runtime APPSYNC_JS e delle relative guide qui.

$util.xmlcontiene metodi di supporto che possono semplificare la traduzione delle risposte XML in JSON o in un dizionario.

Elenco di utilità $util.xml

$util.xml.toMap(String) : Map

Converte una stringa XML in un dizionario.

Input: <?xml version="1.0" encoding="UTF-8"?> <posts> <post> <id>1</id> <title>Getting started with GraphQL</title> </post> </posts> Output (JSON representation): { "posts":{ "post":{ "id":1, "title":"Getting started with GraphQL" } } } Input: <?xml version="1.0" encoding="UTF-8"?> <posts> <post> <id>1</id> <title>Getting started with GraphQL</title> </post> <post> <id>2</id> <title>Getting started with AWS AppSync</title> </post> </posts> Output (JSON representation): { "posts":{ "post":[ { "id":1, "title":"Getting started with GraphQL" }, { "id":2, "title":"Getting started with AWS AppSync" } ] } }
$util.xml.toJsonString(String) : String

Converte una stringa XML in una stringa JSON. È simile a toMap, tranne per il fatto che l'output è una stringa. Questa funzione è utile se si desidera convertire direttamente e restituire la risposta XML da un oggetto HTTP in formato JSON.

$util.xml.toJsonString(String, Boolean) : String

Converte una stringa XML in una stringa JSON con un parametro booleano opzionale per determinare se si desidera codificare il JSON come stringa.