Sure.

public native String getDirectorOfMovie(String movie) /*-{
    return this.movies[movie].director;
}-*/;

As I said, you need to know javascript to do this. Go learn the
basics, you'll figure this out in no time.

On Nov 19, 11:12 pm, "Jose Santa Elena" <[EMAIL PROTECTED]> wrote:
> Thanks again Reinier.
> I've being tryign with by this way, but my problem is accessing associative
> arrays. There is one way to do that?!
>
> On Wed, Nov 19, 2008 at 6:43 PM, Reinier Zwitserloot <[EMAIL PROTECTED]>wrote:
>
>
>
> > Yeah, I kinda sorta did with my new proposed JSON library.
>
> > But you can go even faster.
>
> > Create a java class which mimics essentially exactly the structure of
> > your JSON - with getter methods for everything relevant.
>
> > Give this class NO fields whatsoever, just getters. Then let it extend
> > JavaScriptObject.
>
> > Make each getter native and grab the data straight from the JSON
> > structure. e.g. if you have:
>
> > {'name' = "foobar", 'age'=10}
>
> > you could make:
>
> > public final class Name extends JavaScriptObject {
> >    public native String getName() /*-{ return this.name; }-*/;
> >    public native int getAge() /*-{ return this.age; }-*/;
> > }
>
> > This is exactly as fast as it can possibly be in javascript, as this
> > whole hullabaloo gets eliminated entirely by the compiler. A call to
> > name.getName() will be translated directly to 'name.name' in the
> > javascript.
>
> > You can get arbitrarily funky with your JSON, but you'll need to write
> > all your accessors in javascript, so you'll need to know a thing or
> > two about javascript to build yoru accessor class. Good luck.
> > Make extends JavaScriptObject.
>
> > On Nov 19, 6:51 pm, "Jose Santa Elena" <[EMAIL PROTECTED]> wrote:
> > > Hi all...
> > > Has someone addressed the performance problem on parsing large JSON
> > files?
>
> > > I created one Wrapper to do a "latter bind"...
>
> > > public class JSONMap implements Map {
> > > private JSONObject wrappedJSONObject;
> > >  public JSONMap(JSONObject jsonObject) {
> > > if (jsonObject == null) {
> > > throw new WrongUseException("Invalid JSONObject");}
>
> > >  this.wrappedJSONObject = jsonObject;}
>
> > >  public void clear() {
> > > throw new UnsupportedOperationException();}
>
> > >  public boolean containsKey(Object key) {
> > > throw new UnsupportedOperationException();
>
> > > }
>
> > > public boolean containsValue(Object value) {
> > > throw new UnsupportedOperationException();
>
> > > }
>
> > > public Set entrySet() {
> > > throw new UnsupportedOperationException();}
>
> > >  protected String getKey(Object key) {
> > > String keyValue;
> > >  if (key instanceof String) {
> > > keyValue = (String)key;} else {
>
> > > keyValue = key.toString();
>
> > > }
> > >  return keyValue;
> > > }
>
> > > public Object get(Object key) {
> > > JSONArray jsonArray;
> > > JSONBoolean jsonbBoolean;
> > > JSONNumber jsonNumber;
> > > JSONObject jsonObject;
> > > JSONString jsonString;
> > > JSONValue jsonValue = wrappedJSONObject.get(getKey(key));
> > >  if ((jsonArray = jsonValue.isArray()) != null) {
> > > return new JSONList(jsonArray);} else if ((jsonbBoolean =
> > jsonValue.isBoolean()) != null) {
>
> > > return new Boolean(jsonbBoolean.booleanValue());} else if ((jsonNumber =
> > jsonValue.isNumber()) != null) {
>
> > > return new Double(jsonNumber.doubleValue());} else if ((jsonObject =
> > jsonValue.isObject()) != null) {
>
> > > return new JSONMap(jsonObject);} else if ((jsonString =
> > jsonValue.isString()) != null) {
>
> > > return jsonString.stringValue();} else {
> > > return null;
> > > }
> > > }
>
> > >  public JSONMap getMap(String key) {
> > > return new JSONMap(wrappedJSONObject.get(key).isObject());}
>
> > >  public String getString(String key) {
> > > return wrappedJSONObject.get(key).isString().stringValue();}
>
> > >  public Double getDouble(String key) {
> > > return new Double(wrappedJSONObject.get(key).isNumber().doubleValue());}
>
> > >  public JSONList getList(String key) {
> > > return new JSONList(wrappedJSONObject.get(key).isArray());
>
> > > }
>
> > > public boolean isEmpty() {
> > > return wrappedJSONObject.size() == 0;
>
> > > }
>
> > > public Set keySet() {
> > > return wrappedJSONObject.keySet();
>
> > > }
>
> > > public Object put(Object arg0, Object arg1) {
> > > throw new UnsupportedOperationException();
>
> > > }
>
> > > public void putAll(Map arg0) {
> > > throw new UnsupportedOperationException();
>
> > > }
>
> > > public Object remove(Object key) {
> > > throw new UnsupportedOperationException();
>
> > > }
>
> > > public int size() {
> > > return wrappedJSONObject.size();
>
> > > }
>
> > > public Collection values() {
> > > throw new UnsupportedOperationException();
>
> > > }
> > > }
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Google Web Toolkit" group.
To post to this group, send email to Google-Web-Toolkit@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/Google-Web-Toolkit?hl=en
-~----------~----~----~----~------~----~------~--~---

  • JSON Jose Santa Elena
    • Re: JSON Reinier Zwitserloot
      • Re: JSON Jose Santa Elena
        • Re: JSON Reinier Zwitserloot

Reply via email to