GWT homepage
Overview
Get started
Tutorials
Docs
Resources
Make GWT Better
Terms
Download
Java Doc
Creative Commons Attribution 3.0 License.
Overview
Coding Basics
Introduction
Organize Projects
Compile & Debug
Client-side
JRE Compatibility
Ajax Communication
History Mechanism
Formatting
Delayed Logic
Working with JSON
Working with XML
JavaScript: JSNI
Overlay Types
Deferred Binding
Build User Interfaces
Html5 Support
Test with JUnit
Deploy
Advanced Topics
Reference
FAQ
Glossary
Search
JSON
Many AJAX application developers have adopted JSON as the data format of choice for server communication. It is a relatively simple format based on the object-literal notation of JavaScript. If you choose to use JSON-encoded data within your application, you can use GWT classes to parse and manipulate JSON objects, as well as the very useful and elegant concept of JavaScript Overlay Types.
The JSON format is based on the syntax and data types of the JavaScript language. It supports strings, numbers, booleans, and null values. You can also combine multiple values into arrays and objects. JSON objects are simply unordered sets of name/value pairs, where the name is always a string and the value is any other valid JSON type (even another object). Here’s an example of encoding product data in JSON:
{
"product": {
"name": "Widget",
"company": "ACME, Inc",
"partNumber": "7402-129",
"prices": [
{ "minQty": 1, "price": 12.49 },
{ "minQty": 10, "price": 9.99 },
{ "minQty": 50, "price": 7.99 }
]
}
}
See json.org/example.html for more JSON examples.
Parsing JSON
Mashups with JSON and JSNI
Parsing JSON
You can parse JSON Strings and convert them to a JavaScriptObject using JsonUtils.
/*
* Takes in a JSON String and evals it.
* @param JSON String that you trust
* @return JavaScriptObject that you can cast to an Overlay Type
*/
public static