Re: [json-lib-user] use dot notation implemented anywhere?
Brought to you by:
aalmiray
|
From: Ben A. <tw....@gm...> - 2007-05-01 18:56:30
|
well, here's the simple implementation I put in one of my utility classes
(THIS IS UNTESTED):
public static Object dot(JSONObject jo, String notation) {
Object o =3D null;
try {
String[] tokens =3D notation.split(".");
for (int i=3D0; i<(tokens.length-1); i++) {
jo =3D jo.optJSONObject(tokens[i]);
}
o =3D jo.opt(tokens[tokens.length-1]);
} catch (Exception e) {
// do nothing
}
return o;
On 5/1/07, Andres Almiray <aal...@ya...> wrote:
>
> Ben,
> At this time there is no such thing in Json-lib, but it surely is a cool
> idea.
> If you can submit a patch for it it would be great =3D)
> As an alternative you may switch to Groovy and do something like the
> following
>
> value =3D jsonObject?.schedules?.'2008'?.weeks[1]?.victory
>
> Cheers,
> Andres
> -------------------------------------------
> http://jroller.com/page/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.
>
> ----- Mensaje original ----
> De: Ben Anderson <tw....@gm...>
> Para: jso...@li...
> Enviado: martes, 1 de mayo, 2007 9:04:08
> Asunto: [json-lib-user] use dot notation implemented anywhere?
>
> Hi,
> Is there anything like this?
>
> Boolean v =3D (Boolean) JSONUtils.getValue(jsonObject, "
> schedules.2008.weeks.1.victory");
>
> It'd be nice if I could do this and not have to check for nulls each
> time. For instance, I've been doing this:
>
> Date d =3D null;
> try {
> jsonObject.optJSONObject
> ("schedules").optJSONObject.("2008").optJSONObject("weeks").optJSONObject=
("1").optBoolean("victory");
> } catch (Exception e) {
> // do nothing
> }
>
> Any ideas? If not, I might write my own simple little util that pretty
> much does the above.
>
> Thanks,
> Ben Anderson
> -------------------------------------------------------------------------
> This SF.net email is sponsored by DB2 Express
> Download DB2 Express C - the FREE version of DB2 express and take
> control of your XML. No limits. Just data. Click to get it now.
> http://sourceforge.net/powerbar/db2/
> _______________________________________________
> json-lib-user mailing list
> jso...@li...
> https://lists.sourceforge.net/lists/listinfo/json-lib-user
>
>
> __________________________________________________
> Correo Yahoo!
> Espacio para todos tus mensajes, antivirus y antispam =A1gratis!
> Reg=EDstrate ya - http://correo.yahoo.com.mx/
>
|