XMLajudantes em $util.xml - AWS AppSync

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á.

XMLajudantes em $util.xml

nota

Agora, oferecemos suporte principalmente ao tempo de execução APPSYNC _JS e sua documentação. Considere usar o tempo de execução APPSYNC _JS e seus guias aqui.

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

$util.xml.toMap(String) : Map

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

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

Converte uma XML string em uma JSON string com um parâmetro booleano opcional para determinar se você deseja codificar em string o. JSON