$util.xml 中的 XML 助手 - Amazon AppSync
Amazon Web Services 文档中描述的 Amazon Web Services 服务或功能可能因区域而异。要查看适用于中国区域的差异,请参阅 中国的 Amazon Web Services 服务入门 (PDF)

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

$util.xml 中的 XML 助手

$util.xml包含可以更轻松地将 XML 响应转换为 JSON 或字典的辅助方法。

$util.xml 实用程序列表

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

将 XML 字符串转换为 JSON 字符串。这与 toMap 类似,唯一的不同是输出是一个字符串。如果您要直接转换 XML 响应并将其从 HTTP 对象返回到 JSON,这非常有用。

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

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