Re: [json-lib-user] Problem with special characters in JSON string keys
Brought to you by:
aalmiray
From: Andres A. <aal...@ya...> - 2007-05-28 15:44:04
|
Florian,=0AThe exception is caused by PropertyUtils.setProperty as it parse= s the property name=0Asearching for nested properties (with '.') or mapped/= indexed ones (with '[ ]').=0AJson-lib does not supports nested properties, = but you can alter the name of the target=0Aproperty when transforming from = JSON to Java using a JavaIdentifierTransformer strategy=0A(this does not c= hange the key name on your JSONObject, just the target).=0AThere are 5 defa= ult strategies:=0ANOOP - performs no transformation (default)=0ASTRICT - al= ways throws JSONException if the name is not a valid JavaIdentifier=0ACAMEL= _CASE - transforms the name into camelCase, non-javaIdentifiers are treated= as word boundaries=0AWHITESPACE - chops all whitesspace and non-javaIdenti= fiers from the name=0AUNDERSCORE - chops all '_' and non-javaIdentifiers fr= om the name=0A=0AYou may register a different strategy with JSONUtils.setJa= vaIdentifierTransformer (I think I'm moving that=0Ato JsonConfig as it is n= ow the central place for configuration how parsing should behave).=0A=0AChe= ers,=0AAndres=0A =0A-------------------------------------------=0Ahttp://jr= oller.com/page/aalmiray=0Ahttp://www.linkedin.com/in/aalmiray=0A--=0AWhat g= oes up, must come down. Ask any system administrator.=0AThere are 10 types = of people in the world: Those who understand binary, and those who don'= t.=0ATo understand recursion, we must first understand recursion.=0A=0A----= - Mensaje original ----=0ADe: Florian Shkurti <flo...@gm...>= =0APara: jso...@li...=0AEnviado: lunes, 28 de mayo, = 2007 10:22:49=0AAsunto: [json-lib-user] Problem with special characters in = JSON string keys=0A=0AHi all,=0A=0AI am facing the following problem while = using json-lib:=0A=0A{"array" : [1,2] } =0A=0AWhen I try to convert this JS= ON string into a Java=0Aobject, I get no errors at all; everything works fi= ne.=0A=0AHowever, trying to convert this JSON string =0A=0A{"array.java" : = [1,2]}=0A=0A=0Ainto a Java object yields an error:=0A=0AException in thread= "main" net.sf.json.JSONException: =0Ajava.lang.NoSuchMethodException=0A: = =0AUnknown property 'array'=0A at net.sf.json.JSONObject.toBean(JSONObje= ct.java:543)=0A=0ACaused by: java.lang.NoSuchMethodException: =0AUnknown pr= operty 'array'=0A at org.apache.commons.beanutils=0A=0A .P= ropertyUtilsBean.getSimpleProperty(PropertyUtilsBean.java:1112)=0A at or= g.apache.commons.beanutils=0A .PropertyUtilsBean.setNestedPro= perty(PropertyUtilsBean.java:1619)=0A at org.apache.commons.beanutils=0A= =0A .PropertyUtilsBean.setProperty(PropertyUtilsBean.java:167= 7)=0A at org.apache.commons.beanutils=0A .PropertyUtils.se= tProperty(PropertyUtils.java:559)=0A at net.sf.json.JSONObject.setProper= ty=0A(JSONObject.java:781)=0A at net.sf.json.JSONObject.setProperty(JSON= Object.java:761)=0A at net.sf.json.JSONObject.toBean(JSONObject.java:518= )=0A=0A=0A=0AIt seems that keys that contain period cannot be fully =0A=0Ap= arsed; only the string up to the first period is taken into account.=0AAny = ideas why?=0A=0AThanks in advance,=0AFlorian=0A=0A-------------------------= ------------------------------------------------=0AThis SF.net email is spo= nsored by DB2 Express=0ADownload DB2 Express C - the FREE version of DB2 ex= press and take=0Acontrol of your XML. No limits. Just data. Click to get it= now.=0Ahttp://sourceforge.net/powerbar/db2/=0A____________________________= ___________________=0Ajson-lib-user mailing list=0Aj...@li...ur= ceforge.net=0Ahttps://lists.sourceforge.net/lists/listinfo/json-lib-user=0A= =0A=0A=0A=0A=0A=0A=0A ______________________________________________ = =0A=A1As=F3mbrate! Conoce el Beta de Correo Yahoo! que incluye muchas herra= mientas que har=E1n tu vida m=E1s sencilla.=0Ahttp://correo.yahoo.com.mx/ |