Basic over view of Json / Gson
The basic format of JSON (Javascript Object Notation)
Business object & Property & Value in the JSON
Note: The business object must match with the name of the property
Strength of Gson
- Light-weight languages.
- Similar C-family language but completely independent languages.
- Easy to read & writhe language for humans, easy to parse and manipulate for computer
- JSON is based on a subset on JavaScript
- Provide a class that is used to parse or manipulate Json with java.
Purpose of Gson
- Provide easy-to-use mechanisms like toString() and constructor (factory method) to convert Java to JSON and vice-versa
- Allow pre-existing unmodifiable objects to be converted to and from JSON
- Allow custom representations for objects
- Support arbitrarily complex object
- Generate compact and readable JSON output
Array Examples
Gson gson = new Gson();
int[] ints = {1, 2, 3, 4, 5};
String[] strings = {"abc", "def", "ghi"};
(Serialization)
gson.toJson(ints); ==> prints [1,2,3,4,5]
gson.toJson(strings); ==> prints ["abc", "def", "ghi"]int[] ints = {1, 2, 3, 4, 5};
String[] strings = {"abc", "def", "ghi"};
(Serialization)
gson.toJson(ints); ==> prints [1,2,3,4,5]
(Deserialization)
int[] ints2 = gson.fromJson("[1,2,3,4,5]", int[].class);
==> ints2 will be same as ints
We also support multi-dimensional arrays, with arbitrarily complex element types
Comments
Post a Comment