XML$util.xml 中的助手 - AWS AppSync

本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。

XML$util.xml 中的助手

注意

我们现在主要支持 APPSYNC _JS 运行时及其文档。请考虑在此处使用 APPSYNC _JS 运行时及其指南。

$util.xml包含帮助方法,可以更轻松地将XML回复翻译到JSON或字典。

$util.xml.toMap(String) : Map

将XML字符串转换为字典。

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

将XML字符串转换为字符JSON串。这与类似 toMap,不同之处在于输出是字符串。如果你想直接转换HTTP对象的XML响应并将其返回到,这很有用JSON。

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

将XML字符串转换为带有可选布尔参数的JSON字符串,以确定是否要对字符串进行编码。JSON