我对 Clojure 有点陌生,想知道如何将这个 Enlive 对象转换为 JSON 对象。
我使用下面的 parse 方法解析了一个 XML 文件:
(def xml-parser
(parse "<Vehicle><Model>Toyota</Model><Color>Red</Color><Loans><Reoccuring>Monthly</Reoccuring><Owners><Owner>Bob</Owner></Owners></Loans><Tires><Model>123123</Model><Size>23</Size></Tires><Engine><Model>30065</Model></Engine></Vehicle>"))
并像这样获得了一个 Enlive 对象:
{:tag :Vehicle,
:attrs nil,
:content
[{:tag :Model, :attrs nil, :content ["Toyota"]}
{:tag :Color, :attrs nil, :content ["Red"]}
{:tag :Loans,
:attrs nil,
:content
[{:tag :Reoccuring, :attrs nil, :content ["Monthly"]}
{:tag :Owners,
:attrs nil,
:content [{:tag :Owner, :attrs nil, :content ["Bob"]}]}]}
{:tag :Tires,
:attrs nil,
:content
[{:tag :Model, :attrs nil, :content ["123123"]}
{:tag :Size, :attrs nil, :content ["23"]}]}
{:tag :Engine,
:attrs nil,
:content [{:tag :Model, :attrs nil, :content ["30065"]}]}]}
我希望能够将其转换为 JSON 对象,如下所示:
{:Vehicle {:Model "Toyota"
:Color "Red"
:Loans {:Reoccuring "Monthly"
:Owners {:Owner "Bob"}}
:Tires {
:Model 123123
:Size 23}
:Engine {:Model 30065}}
}
如果使用的词汇不完全准确,我深表歉意
我在这一步转换时遇到了麻烦。提前谢谢你的帮助。