Auxiliares XML em $util.xml - AWS AppSync GraphQL

As traduções são geradas por tradução automática. Em caso de conflito entre o conteúdo da tradução e da versão original em inglês, a versão em inglês prevalecerá.

Auxiliares XML em $util.xml

nota

Agora, oferecemos suporte principalmente ao runtime do APPSYNC_JS e sua documentação. Considere usar o runtime do APPSYNC_JS e seus guias aqui.

$util.xml contém métodos auxiliares que podem facilitar a tradução de respostas XML para JSON ou um dicionário.

Lista de utilitários $util.xml

$util.xml.toMap(String) : Map

Converte uma string XML para um dicionário.

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 uma string XML para uma string JSON. Isso é semelhante a toMap, exceto que a saída é uma string. Isso é útil se quiser converter e retornar diretamente a resposta XML de um objeto HTTP para JSON.

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

Converte uma string XML para uma string JSON com um parâmetro booliano opcional para determinar se deseja codificar o JSON como string.