如何将E4X XML元素转换为JSON表示法 [英] Howto convert E4X XML Elements into JSON Notation

查看:157
本文介绍了如何将E4X XML元素转换为JSON表示法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个服务器实施ECMA脚本,包括使用E4X的能力.因为这对于不懂JavaScript和JSON表示法的人来说非常优雅,所以我们想制作一个最容易学习的API,我想将其用于我的API.

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.

我目前正在评估是否可以在我的环境中使用它.我必须使用的一种Showstopping功能是即时将E4X的XML对象转换为JSON兼容的JavaScript对象或字符串.我不能在这里使用XSLT,因为我必须留在JavaScript中.

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.

问题是,有没有一种简单的方法可以将E4X XML元素转换为JSON?还是我必须编写一些代码自行转换?

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?

推荐答案

您可以使用XSLT将XML转换为JSON.

You can use XSLT to convert your XML to JSON.

例如使用以下内容: http://code.google.com/p/xml2json-xslt /

但是,最终您会得到非常XMLish且不必要复杂的JSON.这将使您的代码更难以编写和维护.

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

API通常意味着时间稳定,因此对于每个调用,可能有一些专用的XSLT比通用的API更好.

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.

这篇关于如何将E4X XML元素转换为JSON表示法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆