Google Groups Home
Help | Sign in
JSONObject bug
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  2 messages - Collapse all
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
vsmak  
View profile
(1 user)  More options Aug 16 2006, 5:37 pm
From: "vsmak" <vees...@gmail.com>
Date: Wed, 16 Aug 2006 14:37:36 -0700
Local: Wed, Aug 16 2006 5:37 pm
Subject: JSONObject bug
Hello,

I've run into a bug with putting JSONObjects inside of JSONObjects.
Here's some sample code.

public void onModuleLoad()
{
JSONObject j1 = new JSONObject();
j1.put("test1", new JSONString(""));

JSONObject j2 = new JSONObject();
j2.put("test1", new JSONString(""));

JSONObject j3 = new JSONObject();
j3.put("j1", j1);
j3.put("j2", j2);

Window.alert(j3.toString());

}

The expected output is:
{"j1":{"test1":""}, "j2":{"test1":""}}

But instead it returns:
{"test1":{"test1":""}, "test1":{"test1":""}}

Thanks. Is there a workaround until the next patch is released?


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Henry  
View profile
(3 users)  More options Aug 17 2006, 11:32 pm
From: "Henry" <h...@google.com>
Date: Thu, 17 Aug 2006 20:32:59 -0700
Local: Thurs, Aug 17 2006 11:32 pm
Subject: Re: JSONObject bug
That is a bug -- thanks for finding it. You can work around it by
calling the alternative toString() routine below. Just put this static
function in a class (e.g. JSONPatch), and replace
xxxx.yyyy.zzzz.JSONPatch with the package name you've chosen.

The bug has already been fixed and will be included in the next GWT
release.

       Thanks again,

                 Henry

  /**
   * Converts a JSONObject into a JSON representation that can be used
to
   * communicate with a JSON service.
   *
   * @return a JSON string representation of this JSONObject instance
   */
  public static native String toStringJSONObject(JSONObject obj) /*-{
    for(var x in
th...@com.google.gwt.json.client.JSONObject::backStore) {
      // we are wrapping everything in backStore so that frontStore is
canonical

th...@com.google.gwt.json.client.JSONObject::get(Ljava/lang/String;)(x
);
    }
    var out = [];
    out.push("{");
    var first = true;
    for(var x in o...@com.google.gwt.json.client.JSONObject::frontStore
) {
      if(first) {
        first = false;
      } else {
        out.push(", ");
      }
      var subItem =
(o...@com.google.gwt.json.client.JSONObject::frontStore[x ]);
      var subObj=null;

if(!(subIt...@com.google.gwt.json.client.JSONValue::isObject()())) {

        subObj =
(subItem)....@com.google.gwt.json.client.JSONValue::toString ()();
      } else {
        subObj =

@xxxx.yyyy.zzzz.JSONPatch::toStringJSONObject(Lcom/google/gwt/json/client/J SONObject;)(subItem);
      }
      out.push("\"");
      out.push (x);
      out.push("\":");
      out.push(subObj);
    }
    out.push("}")
    return out.join("");
  }-*/;


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2008 Google