View a markdown version of this page

Assistants XML dans util.xml - AWS AppSync GraphQL

Les traductions sont fournies par des outils de traduction automatique. En cas de conflit entre le contenu d'une traduction et celui de la version originale en anglais, la version anglaise prévaudra.

Assistants XML dans util.xml

util.xmlcontient des méthodes pour faciliter la conversion de chaînes XML.

liste des utilitaires util.xml

util.xml.toMap(String) : Object

Convertit une chaîne XML en dictionnaire.

Exemple 1 :

Input: <?xml version="1.0" encoding="UTF-8"?> <posts> <post> <id>1</id> <title>Getting started with GraphQL</title> </post> </posts> Output (object): { "posts":{ "post":{ "id":1, "title":"Getting started with GraphQL" } } }

Exemple 2 :

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 AppSync</title> </post> </posts> Output (JavaScript object): { "posts":{ "post":[ { "id":1, "title":"Getting started with GraphQL" }, { "id":2, "title":"Getting started with AppSync" } ] } }
util.xml.toJsonString(String, Boolean?) : String

Convertit une chaîne XML en chaîne JSON. C'est similaire àtoMap, sauf que la sortie est une chaîne. Cela est utile si vous souhaitez convertir et renvoyer directement la réponse XML à partir d'un objet HTTP vers JSON. Vous pouvez définir un paramètre booléen facultatif pour déterminer si vous souhaitez encoder le JSON sous forme de chaîne.