Showing posts with label JSON. Show all posts
Showing posts with label JSON. Show all posts

Saturday, February 9, 2013

Url encode an HTTP GET Solr request and parse json using gson java library

Make a request to the SOLR webserver and parse the json string to Java classes using the code snippets below.
The JSON to be parsed- The corresponding Java classes- Code snippet to make a web server call and parse using gson-

The Java classes must have the same variable names as the Json's keys. Notice how nested Json elements are handled.

Thursday, March 5, 2009

JSON

JSON is an acronym for JavaScript Object Notation. It is a means of transferring serialized JavaScript objects so that a JavaScript application can evaluate them and transform them into JavaScript objects which, the application can utilize to perform its operations. In short, JSON is a data interchange format. It is easy to parse and generate in almost any language.

A sample JSON:-
{"continents": {
"asia":[{"country": "india",
"code": "101"
},
{"country": "japan",
"code": "102"
}],
"europe":[{"country": "france",
"code": "401"
}]
}
}


The most notable features of JSON are:-

1.
It is basically a collection of name-value pairs ("key": "value") separated by a colon.
2.
It is not only easy to read for humans but also easy to parse by the machines.
3. Values can be a string, an integer, an object or an array.
Standard literals like True, False, null are also acceptable.
4. Each object is placed between {...}.
5. Arrays are place between [...] and are comma separated.
6. It can be passed using httpWebRequest.
7. Reserved keywords from JavaScript are not allowed in JSON.
8. JSON can be parsed using the eval() method in JavaScript.
9. It uses Unicode.


Common errors like the "missing } after property list" can be corrected
using a JSON validator like www.jsonlint.com