我有这个 XML; https://www.ecb.europa.eu/stats/eurofxref/eurofxref-daily.xml 我需要解析以生成 JSON。我有这个模板
require 'json'
require 'rexml/document'
include REXML
def main(orchAttr, inputMap)
jsonIn = JSON.parse(inputMap)
jsonOut = JSON.parse("{}")
#XML Example
#xml_str = jsonIn["response"]
#doc = Document.new(xml_str)
#city = doc.elements["AddressValidateResponse/Address/City"].text
#jsonOut["city"] = city
return JSON.generate(jsonOut)
end
但是当我做一些修改时,我得到了一个错误。
我修改了这一行
#city = doc.elements["AddressValidateResponse/Address/City"].text
使用 XML 元素
你为什么不使用 ecb api rest?它对编排程序很有用,您可以获得汇率并通过表单请求添加到 P0015A https://sdw-wsrest.ecb.europa.eu/help/