Re: [json-lib-user] XML -> JSON, "type" attribute omitted?
Brought to you by:
aalmiray
From: John C. <Joh...@no...> - 2007-12-06 17:32:28
|
Strangely, I found that whitespace seems to trigger the anomalous behavior. If I remove all whitespace between elements, the FEATURES element re-appears in the JSON representation regardless of how many FEATURE children there are. --john Andres Almiray wrote: > Then it is as I suspected, that the serializer thinks FEATURES should > be treated as an array rather than as an object, which is strange as > in the first example you can clearly see 3 named elements on FEATURES. > I'll check it tonight and let you know what I found. > > Cheers, > Andres > > > ----- Original Message ---- > From: John Cartwright <Joh...@no...> > To: Andres Almiray <aal...@ya...> > Cc: jso...@li... > Sent: Wednesday, December 5, 2007 4:01:16 PM > Subject: Re: [json-lib-user] XML -> JSON, "type" attribute omitted? > > Thanks for the prompt reply! This is a version that I compiled from CVS > that includes the fix you made on 10/14: > > > It wasn't that difficult after all, the fix is already on the cvs, > > here is the link to the FR > > > http://sourceforge.net/tracker/index.php?func=detail&aid=1813520&group_id=171425&atid=857931 > <http://sourceforge.net/tracker/index.php?func=detail&aid=1813520&group_id=171425&atid=857931> > > > > <http://sourceforge.net/tracker/index.php?func=detail&aid=1813520&group_id=171425&atid=857931 > <http://sourceforge.net/tracker/index.php?func=detail&aid=1813520&group_id=171425&atid=857931>> > > I confirmed that it doesn't have to do w/ the element name itself. It > does however seem to be related to the number of FEATURE elements. The > following is the XML/JSON result produced when FEATURES includes > multiple FEATURE children: > > <?xml version="1.0" encoding="UTF-8"?> > <ARCXML version="1.1"> > <RESPONSE> > <FEATURES> > <FEATURE> > <ENVELOPE minx="-81.5650024414062" miny="23.0499992370605" > maxx="-81.5650024414062" maxy="23.0499992370605"/> > <FIELDS> > <FIELD name="CITY_NAME" value="Matanzas" /> > <FIELD name="GMI_ADMIN" value="CUB-MTN" /> > <FIELD name="ADMIN_NAME" value="Matanzas" /> > </FIELDS> > </FEATURE> > <FEATURE> > <ENVELOPE minx="-82.4164505004883" miny="23.0489521026611" > maxx="-82.4164505004883" maxy="23.0489521026611"/> > <FIELDS> > <FIELD name="CITY_NAME" value="Havana" /> > <FIELD name="GMI_ADMIN" value="CUB-CHB" /> > <FIELD name="ADMIN_NAME" value="Ciudad de la Habana" /> > </FIELDS> > </FEATURE> > <FEATURECOUNT count="14" hasmore="false" /> > </FEATURES> > </RESPONSE> > </ARCXML> > > {"RESPONSE":{"FEATURES":{"FEATURECOUNT":{"@hasmore":"false","@count":"14"},"FEATURE":[{"ENVELOPE":{"@minx":"-81.5650024414062","@maxy":"23.0499992370605","@maxx":"-81.5650024414062","@miny":"23.0499992370605"},"FIELDS":[{"@value":"Matanzas","@name":"CITY_NAME"},{"@value":"CUB-MTN","@name":"GMI_ADMIN"},{"@value":"Matanzas","@name":"ADMIN_NAME"}]},{"ENVELOPE":{"@minx":"-82.4164505004883","@maxx":"-82.4164505004883","@maxy":"23.0489521026611","@miny":"23.0489521026611"},"FIELDS":[{"@value":"Havana","@name":"CITY_NAME"},{"@value":"CUB-CHB","@name":"GMI_ADMIN"},{"@value":"Ciudad > > de la Habana","@name":"ADMIN_NAME"}]}]}},"@version":"1.1"} > > > -- john > > Andres Almiray wrote: > > Hi John, > > > > No, in this case seems to be something else, perhaps corner case where > > XMLSerializer can't decide if FEATURES should be a JSONObject instead > > of a JSONArray. To me it should be something like > > > > { > > RESPONSE: > > { > > FEATURES: > > { > > ... > > } > > } > > } > > > > Are you getting this result with Json-lib 2.1 ? > > > > -- Andres > > > > ----- Original Message ---- > > From: John Cartwright <Joh...@no... > <mailto:Joh...@no...>> > > To: Andres Almiray <aal...@ya... <mailto:aal...@ya...>> > > Cc: jso...@li... > <mailto:jso...@li...> > > Sent: Wednesday, December 5, 2007 3:42:47 PM > > Subject: Re: [json-lib-user] XML -> JSON, "type" attribute omitted? > > > > Hi Andres, > > > > is it possible that an XML element named features would have the same > > trouble? I'm finding the XML listed below is serializing to JSON w/o > > that element. > > > > Thanks! > > > > -- john > > > > <?xml version="1.0" encoding="UTF-8"?> > > <ARCXML version="1.1"> > > <RESPONSE> > > <FEATURES> > > <FEATURE> > > <ENVELOPE minx="-178.216552734375" miny="18.9254779815674" > > maxx="179.775939941406" maxy="71.3514404296875"/> > > <FIELDS> > > <FIELD name="FIPS_CNTRY" value="US" /> > > <FIELD name="GMI_CNTRY" value="USA" /> > > <FIELD name="ISO_2DIGIT" value="US" /> > > <FIELD name="ISO_3DIGIT" value="USA" /> > > <FIELD name="CNTRY_NAME" value="United States" /> > > <FIELD name="LONG_NAME" value="United States" /> > > <FIELD name="SOVEREIGN" value="United States" /> > > <FIELD name="POP_CNTRY" value="258833000" /> > > <FIELD name="CURR_TYPE" value="US Dollar" /> > > <FIELD name="CURR_CODE" value="USD" /> > > <FIELD name="LANDLOCKED" value="N" /> > > <FIELD name="SQKM" value="9449365" /> > > <FIELD name="SQMI" value="3648399.75" /> > > <FIELD name="COLORMAP" value="5" /> > > <FIELD name="#SHAPE#" value="[Geometry]" /> > > <FIELD name="#ID#" value="234" /> > > </FIELDS> > > </FEATURE> > > <FEATURECOUNT count="1" hasmore="false" /> > > <ENVELOPE minx="-178.216552734375" miny="18.9254779815674" > > maxx="179.775939941406" maxy="71.3514404296875"/> > > </FEATURES> > > </RESPONSE> > > </ARCXML> > > > > > {"RESPONSE":[{"ENVELOPE":{"@miny":"18.9254779815674","@minx":"-178.216552734375","@maxy":"71.3514404296875","@maxx":"179.775939941406"},"FEATURECOUNT":{"@hasmore":"false","@count":"1"},"FEATURE":{"ENVELOPE":{"@miny":"18.9254779815674","@minx":"-178.216552734375","@maxy":"71.3514404296875","@maxx":"179.775939941406"},"FIELDS":[{"@name":"FIPS_CNTRY","@value":"US"},{"@name":"GMI_CNTRY","@value":"USA"},{"@name":"ISO_2DIGIT","@value":"US"},{"@name":"ISO_3DIGIT","@value":"USA"},{"@name":"CNTRY_NAME","@value":"United > > > > > States"},{"@name":"LONG_NAME","@value":"United > > States"},{"@name":"SOVEREIGN","@value":"United > > > States"},{"@name":"POP_CNTRY","@value":"258833000"},{"@name":"CURR_TYPE","@value":"US > > > > > > Dollar"},{"@name":"CURR_CODE","@value":"USD"},{"@name":"LANDLOCKED","@value":"N"},{"@name":"SQKM","@value":"9449365"},{"@name":"SQMI","@value":"3648399.75"},{"@name":"COLORMAP","@value":"5"},{"@name":"#SHAPE#","@value":"[Geometry]"},{"@name":"#ID#","@value":"234"}]}}],"@version":"1.1"} > > > > > > Andres Almiray wrote: > > > Hi John, > > > > > > Sorry for the late reply. The answer is yes and no, let me explain. > > > XMLSerializer has an option to expose a value's type when serializing > > > JSON to XML, that information is written as an attribute named 'type'. > > > When reading it is assumed you want to recover that information if > > > 'type' is an attribute of a node, but it seems that in your case type > > > has a business meaning and should be treated like that instead of a > > > construct of the library. The same will happen with an attributed > > > named 'class' by the way. > > > > > > Let me look for an alternative that is backward compatible at the same > > > time. > > > > > > Cheers, > > > Andres > > > > > > ------------------------------------------- > > > http://jroller.com/page/aalmiray > > > http://www.linkedin.com/in/aalmiray > > > -- > > > What goes up, must come down. Ask any system administrator. > > > There are 10 types of people in the world: Those who understand > > > binary, and those who don't. > > > To understand recursion, we must first understand recursion. > > > > > > > > > ----- Original Message ---- > > > From: John Cartwright <Joh...@no... > <mailto:Joh...@no...> > > <mailto:Joh...@no... <mailto:Joh...@no...>>> > > > To: jso...@li... > <mailto:jso...@li...> > > <mailto:jso...@li... > <mailto:jso...@li...>> > > > Sent: Monday, October 8, 2007 10:29:37 AM > > > Subject: [json-lib-user] XML -> JSON, "type" attribute omitted? > > > > > > Hello All, > > > > > > It seems to me that when converting XML to JSON, elements w/ an > > > attribute named "type" have that attribute omitted. Is this expected > > > behavior? > > > > > > Thanks! > > > > > > -- john > > > > > > > > > > > > ------------------------------------------------------------------------- > > > This SF.net <http://SF.net> <http://SF.net> email is sponsored by: > Splunk Inc. > > > Still grepping through log files to find problems? Stop. > > > Now Search log events and configuration files using AJAX and a > browser. > > > Download your FREE copy of Splunk now >> http://get.splunk.com/ > > > _______________________________________________ > > > json-lib-user mailing list > > > jso...@li... > <mailto:jso...@li...> > > <mailto:jso...@li... > <mailto:jso...@li...>> > > > https://lists.sourceforge.net/lists/listinfo/json-lib-user > > > > > > > > > > ------------------------------------------------------------------------ > > > Catch up on fall's hot new shows > > > > > > <http://us.rd.yahoo.com/tv/mail/tagline/falltv/evt=47093/*http://tv.yahoo.com/collections/3658%20> > > > > > > on Yahoo! TV. Watch previews, get listings, and more! > > > > > > ------------------------------------------------------------------------ > > Be a better friend, newshound, and know-it-all with Yahoo! Mobile. Try > > it now. > > > <http://us.rd.yahoo.com/evt=51733/*http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ%20> > > > ------------------------------------------------------------------------ > Never miss a thing. Make Yahoo your homepage. > <http://us.rd.yahoo.com/evt=51438/*http://www.yahoo.com/r/hs> |