开发者

Howto convert E4X XML Elements into JSON Notation [duplicate]

开发者 https://www.devze.com 2023-02-17 23:04 出处:网络
This question already has answers here: Convert XML to JSON (and back) using Javascript (14 answers) 开发者_运维技巧Closed 8 years ago.
This question already has answers here: Convert XML to JSON (and back) using Javascript (14 answers) 开发者_运维技巧 Closed 8 years ago.

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?


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消