h0nza / x2js

Automatically exported from code.google.com/p/x2js
0 stars 0 forks source link

xml_str2json had _asArray attribute that shoulde be a option #12

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
When i use xml_str2json to get json object. It's work but that json had 
[_asArray] attribute. The [_asArray] attribute was not work in my project.
So if you can let that attribute to option mode that be great.

Original issue reported on code.google.com by bbdragoner@gmail.com on 9 Aug 2013 at 7:28

GoogleCodeExporter commented 9 years ago
Hello! Thanks for the report!
What do you think about element.element.asArray format instead current?
I mean like an additional function (like toString).

Original comment by abdulla....@gmail.com on 9 Aug 2013 at 9:53

GoogleCodeExporter commented 9 years ago
or 
<element>...<element>.__asArray

Original comment by abdulla....@gmail.com on 9 Aug 2013 at 10:00

GoogleCodeExporter commented 9 years ago
I suggest you can set a option like needArray. if that is false then don't 
create _asArray attribute.

Because many project need auto generate infomation from json data. like below
            for (var p in jsonData.rows[0]) {
                if (p != "rowStyle" && p != "cellStyle") {
                    var col = this.getDefaultColumn();
                    col.field = p;
                    col.title = p;
                    this.addColumn(col);
                }
            }

Original comment by bbdragoner@gmail.com on 10 Aug 2013 at 1:49

GoogleCodeExporter commented 9 years ago
But it looks like if I change <element_>asArray _property_ format to 
<element>.__asArray _function_ (like toString()) there is no need for an 
additional option, isn't?

Original comment by abdulla....@gmail.com on 10 Aug 2013 at 1:27

GoogleCodeExporter commented 9 years ago
If you change to <element>.__asArray then <element> will be object type not 
string type right??
And I dno't understand what need __asArray. Beacuse my origin json is not had 
this...

Original comment by bbdragoner@gmail.com on 12 Aug 2013 at 1:58

GoogleCodeExporter commented 9 years ago
Yes, it will be Object type with toString(). But you shouldn't expect always 
string there. If you have CDATA, attributes, namespace in your XML element you 
will receive Object (with additional properties).

__asArray is required to work with XML to access fields always in array form 
(for XSD elements with minOccurs > 1). X2JS can't detect array/single element 
without XSD knowledge in runtime.

Original comment by abdulla....@gmail.com on 12 Aug 2013 at 8:50

GoogleCodeExporter commented 9 years ago
But many XML use is simply for javascript. So I think may be can use a option 
to check what is user want to use.

I found another code can use to my project. You can see to 
http://goessner.net/download/prj/jsonxml/. This jsonxml I was foun in jqGrid. 
But It's not include xmlstr to json function.

Original comment by bbdragoner@gmail.com on 12 Aug 2013 at 9:33

GoogleCodeExporter commented 9 years ago
Well, ok. I will think about additional option for __asArray. Maybe for some 
cases it is redundant.

Original comment by abdulla....@gmail.com on 12 Aug 2013 at 10:58

GoogleCodeExporter commented 9 years ago
Fixed in 1.1.0

Original comment by abdulla....@gmail.com on 12 Aug 2013 at 1:54

GoogleCodeExporter commented 9 years ago

Original comment by abdulla....@gmail.com on 29 Sep 2013 at 3:14