Gson is a JSON serialization/deserialization tool released by Google that is very easy to use. This article briefly discusses how to exclude certain fields when you use Gson to turn Java objects into JSON.The simplest usageSuppose you have the following class:1 classMYOBJ {2 3 Public intx;4 Public inty;5 6 PublicMYOBJ (intXinty) {7 This. x =x;8 This. y =y;9 }Ten}The simplest Gso
There are already open source projects that convert Java objects to JSON. But most projects require you to add Java annotations to the class file, which is not possible when you can't change the source code. And they do not support Java generics either. But Gson the two points as a very important design goal.
Characte
(xmlhttp.readystate = = 4) {
if (Xmlhttp.status = = 200) {
document.getElementById ("Response"). InnerHTML = Xmlhttp.responsetext;
}
}
}
The user-entered account information is packaged as an object and is converted to JSON format using JSON-augmented tojsonstring (), then POST to the server, and the server can download the JSON-server Parser from
Recently, my younger brother used JSON. After learning about it, it's quite simple. He just needs to make some preparations before getting started.
Download the jarpackage at http://json-lib.sourceforge.net/on the JSON official website. You can also see on the official website that other jar packages are required to use JSON
-collections.jar4.commons-logging.jar5.ezmorph.jar6.json-lib-2.2.2-jdk15.jarUsage Ibid.Jsonobject jsonobject = jsonobject.fromobject (message);GetResponse (). Getwriter (). Write (jsonobject.tostring ());When the data is converted to JSON, it is sent to the client using the method as above. The front end is ready to get JSON data.can also be used List list1 = new
": False, "username": "", "Age": 0}]3. Map to JSONhashmapMap.put ("name", "HZUCMJ"); Map.put ("Age", 22);Jsonobject json = jsonobject.fromobject (list);System.out.println (Json.tostring ());The result is:{"Name": "HZUCMJ", "Age": 22}Based on the Json-lib.jar packet Jsonobject-java common four kinds of usageBased on Json
1. Convert the list of Java objects to an array of JSON objects and move to a stringJsonarray array = jsonarray.fromobject (userlist);String jsonstr = array.tostring ();2. Converting Java objects to JSON objects and converting them into stringsJsonobject Object = Jsonobject.fromobject (invite);String str=object.tostrin
Transferred from: http://blog.csdn.net/wilsonke/article/details/24362851The role of a simple and convenient data transmission scheme, JSON has become an alternative to XML fact standard. However, in JSON, the time (datetime,timestamp,date, etc.) format has not been well-integrated, and when cross-platform serialization/deserialization is required, there is a lot of trouble. The author has repeatedly tried t
jsonobj = new Jsonobject (); Add Data jsonobj.put ("username", "Wanglihong") to the JSON; Jsonobj.put ("height", 12.5); Jsonobj.put ("Age", 24); Create a Jsonarray array and add the JSON to the array jsonarray = new Jsonarray (); Array.put (Jsonobj); Convert to String jsonstr = Array.tostring ();
Java uses JDBC Connection database to do JSON encapsulation and parsing examples
This example is an example of using SOLServer2007 to connect a database with JDBC and to query the data format encapsulated into JSON.
Directly on the code--
Main function
Package Com.kuatang.jsondatas;
Import Java.io.File;
Import java.util.ArrayList;
Import Java.util.HashMap
Analysis of C/C ++, Java, PHP, JavaScript, Json array, object Value assignment can be followed by a comma, javascriptjson
1 C, C ++, Java, and PHP can tolerate commas at the end
When values are assigned to arrays in C, C ++, and Java, the comma at the end of the last element is dispensable. The following two lines of c
1:php Address Http://127.0.0.6/?c=json
The result of the 2:java output is
[{' id ': 1, ' name ': ' ZHDC '},{' id ': 2, ' name ': ' \u5c0f\u6731 '}]
index.php
Main.class import Java.io.BufferedInputStream;
Import java.io.IOException;
Import Java.io.InputStream;
Import Java.io.InputStreamReader;
Import Java.io.Reader;
Import java.net.HttpURLConnection;
Import java.net.MalformedURLE
There are two types of structures in the JSON structure:JSON is simply called objects and arrays in JavaScript, so these two structures are objects and arrays of two structures that can represent a variety of complex structures.1. Object: The object in JS is represented as "{}" in the content, the data structure is {Key:value,key:value,...} The structure of key-value pairs, in object-oriented languages, key is the property of the object, value is the
Converts a JSON-formatted "array" string to a Java object "array".Apply this technique to get a Java-corresponding object from a JSON object string format.Jsonobject is a "name.values" collection,The value portion (string) corresponding to key is obtained by the Get (key) method.A Jsonobject object can be obtained by G
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.