Howto convert E4X XML Elements into JSON Notation [duplicate]

末鹿安然 提交于 2019-12-11 01:42:58

问题


I have a server Implementation of ECMA Script including the ability to use E4X. Because this is pretty elegant for people don't know JavaScript and JSON Notation and we want to make an API which is most easy to learn i want to use this for my API.

I'm currently evaluating if i can use this in my environment. One Showstopping feature that i must use is to convert those XML Objects of E4X into JSON compatible JavaScript Objects or Strings on the fly. I can't use XSLT here because i have to stay inside JavaScript.

So the question is, is there an easy way to convert E4X XML Elements into JSON? Or do i have to write some code to convert it myself?


回答1:


You can use XSLT to convert your XML to JSON.

For instance using: http://code.google.com/p/xml2json-xslt/

However you can end up with a very XMLish and unnecessarily complex JSON. That will make your code more difficult to write and maintain.

An API is generally meant to be stable in time, so may be some dedicated XSLT for each calls may be a better option than a generic one.



来源:https://stackoverflow.com/questions/5340461/howto-convert-e4x-xml-elements-into-json-notation

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!