I have a need to load some static data in JSON format that initializes
some of the widgets in the screen.
It would advantageous to me if that static data where already loaded
and ready to be used before the gwt logic kicks in.
Alternatively I could use async http requests to pick it up but it's
not very graceful.
The JSON static data is made mostly of JSON arrays (strings and
numbers). I tried JSNI but couldn't find a easy way to load those
simple JSON objects into the GWT.
I wonder if someone have come across that and have an easy way to do
that.
Thanks in advance!
example.js
//<![CDATA[
var my_array_of_elements=["elem1","elem2","elem3"];
//]]>
myHtml.html
<html>
<head>
<script language='javascript' src='example.js'></script>
<script src="gwt...js"></script>
</head>
...
</hmtl>
and my question is
how do it get the "my_array_of_elements" into, lets say, a JSONArray?
is there a simple way to do that?
Thanks!
Regarding the rocket-gwt link .. I don't get it ...
I copy below an extract from that documentation
>>
"Include required import statements.
import rocket.json.client.JsonSerializer;
To de serialize a json object to java a reference a JsonSerializer
must obtained using deferred binding.
JSONObject jsonObject = // already got it from somewhere...
JsonSerializer serializer = (JsonSerializer)
GWT.create( SomeClass.class );
>>
So it says the JSONObject is already gotten from somewhere ... well
that's precisely what I like to know. How do I get it there?
Thanks
On Nov 13, 4:44 pm, "Milan Jaric" <milan.ja...@gmail.com> wrote:
> Json is short of Java Script Object Notation
>
> so when you declare an object with anonymous constructor in javascript you
> do this
> vara anObject = {
> property1 : "property one is text",
> property2 : new function(param){ return param }
>
> }
>
> so JSON will look like this
>
> var JSONObject = {"objects": [ // <---- start of array
> {"property1": "PRIVMSG", "property2": "newURI" }, // <-- this is
> object1
> {"property1": "PRIVMSG", "property2": "deleteURI" }, // <-- this is
> object2
> {"property1": "PRIVMSG", "property2": "randomURI", } // etc...
> ]
>
> };
>
> and gwt support for this ishttp://code.google.com/p/rocket-gwt/wiki/JsonSerialization
e.g.
private native JavaScriptObject readJSObject () /*-{
return $wnd.my_array_of_elements;
}-*/;
public void foo () {
JavaScriptObject js= null;
JSONArray ja=null;
js = readJSObject();
ja=new JSONObject(js);
}
So now "ja" will have the array as a JSONArray object in GWT.
if the JavaScript were a more complex JSON structure such us
var my_json_object = { key1:[1,2,3,4];key2:"hello";key3:{morekeys:
["a","b"];}}
then in the foo() method instead of having a JSONArray simply have a
JSONObject
regards,
Peter