Comments (4)
Updated by darron.schall on 2006-12-29T21:02:55
Changed issue title (accidentally left it as default when I entered it).
Title changed from 'JSON does not encode XML instances into anything useful' to 'JSON does not encode XML instances into anything useful'
from as3corelib.
Updated by mikechambers on 2007-01-10T04:41:34
I believe Firefox 2 has support for e4x. Might be useful to see how they handle it.
from as3corelib.
For me, converting XML to JSON has three major issues to be resolved: a) what do to about the XML root element name? b) how to encode attributes? c) how to encode text nodes when the parent element has attributes or other element children?
To that end, I added an xmlToString() function to JSONEncoder and a JSONEncoderXMLOptions class as an optional parameter to the JSONEncoder constructor. Let's say you have this XML:
<root>
<category>Sci-Fi</category>
<books>
<book id="1">Text for Book 1</book>
<book id="2">Text for Book 2</book>
</books>
</root>
Option omitRootElement:Boolean;
Sometimes you want the JSON version to simply be { "books" : [ etc. ] }
. And sometimes you want everything: { "root" : { "books" : [ etc. ] } }
.
Option useAttributeAtSymbol:Boolean
Defaults to true
. Determines whether or not attributes should be encoded with an @ sign at the beginning, like "@id" : "1"
I think this should be standard, but I've set it as an option because I've seen implementations where they don't use @. IMO, if you can't differentiate attributes, you can't turn the JSON back into XML.
Option defaultSimpleContentLabel:String
Defaults to #text
. A simple element like <category>
can have its text node as its only value, like "category" : "Sci-Fi"
. But the text node of <book>
needs its own property name, which in this case would look like: "book" : { "@id" : "1", "#text" : "Text for Book 1" }
.
Other implementations use "label" but that's already a common property name for many actionscript objects.
I'll see if I can offer a patch, at least as a reference.
from as3corelib.
I've pushed my changes to my fork: https://github.com/demauk/as3corelib/tree/master/src/com/adobe/serialization/json
There are kind of a lot of changes in that one commit. Sorry about that.
from as3corelib.
Related Issues (20)
- URI.isDirectory is broken
- Fat SWC for better code completion
- library is incompatible with Flash Builder 4.5 HOT 6
- Getting error while running example on win7/FB451 and Flashplayer 10
- Error parsing JSON: Unexpected end of input - Comments
- MD5.digest.endian should be LITTLE_ENDIAN(patch included)
- Include SWC in git HOT 3
- the JSON class conflicts with the Native JSON class for FlashPlayer 11 HOT 2
- The HMAC-SHA1 signature generated is different for Ubuntu JAUNTY
- JSONEncoder.objectToString() fails when the object has "internal" property
- JSON.decode undefined method HOT 3
- URI should use escape/unescape (ascii) as opposed to encode/decodeURI (UTF8)
- StringUtil
- JSONencode can't change output names
- JSON class not working when exporting to AIR — #1065: Variable JSON is not defined HOT 1
- importing JPGEncoder
- URI breaks query strings containing `=` symbol
- SHA set int var with number > int.MAX_VALUE
- Base64Encoder DOES NOT WORK WITH FLASH PROFESSIONAL OR ANIMATE CC
- [Bug] JPGEncoder.encode problem with loaded image's bitmap data
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from as3corelib.