You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Originally filed by darron.schall on 2006-12-29T21:02:09
What steps will reproduce the problem?
trace( JSON.encode( ) );
What is the expected output? What do you see instead?
Like Date instance (see issue #2), there is no standard XML encoding syntax
defined for JSON. Because E4X is a core part of ECMAScript Edition 4, I
would suspect that the JSON-encoded XML would just use <> like an XML literal.
So, the above trace would produce the following JSON string:
var arr:Arary = new Array();
arr.push( );
arr.push( true );
trace( JSON.encode( arr ) );
... should probably output: "[,true]"
The current output is {}, which is clearly not good, no matter what the
expected output should be.
Please use labels and text to provide additional information.
There needs to be a consensus on what the expected output should be before
this is addressed.
This could spring into a religious debate, "Why on earth would anyone want
to encode XML in JSON? It's apples and oranges!"... but rather than get
into politics, I'd rather just agree on a universal solution / standard for
dealing with XML instances in JSON encoding.
The text was updated successfully, but these errors were encountered:
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>
<bookid="1">Text for Book 1</book>
<bookid="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.
Originally filed by darron.schall on 2006-12-29T21:02:09
What steps will reproduce the problem?
What is the expected output? What do you see instead?
Like Date instance (see issue #2), there is no standard XML encoding syntax
defined for JSON. Because E4X is a core part of ECMAScript Edition 4, I
would suspect that the JSON-encoded XML would just use <> like an XML literal.
So, the above trace would produce the following JSON string:
"<test attr1="test" attr2="42"><child1 childAttr1="false" />"
Along the same lines, the following:
var arr:Arary = new Array();
arr.push( );
arr.push( true );
trace( JSON.encode( arr ) );
... should probably output: "[,true]"
The current output is {}, which is clearly not good, no matter what the
expected output should be.
Please use labels and text to provide additional information.
There needs to be a consensus on what the expected output should be before
this is addressed.
This could spring into a religious debate, "Why on earth would anyone want
to encode XML in JSON? It's apples and oranges!"... but rather than get
into politics, I'd rather just agree on a universal solution / standard for
dealing with XML instances in JSON encoding.
The text was updated successfully, but these errors were encountered: