在美元實用程序的 XML 助手 - AWS AppSync

本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。

在美元實用程序的 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 進行字串編碼。