Original link: http://www.cnblogs.com/lanxuezaipiao/archive/2013/05/23/3096001.htmlA lot of JSON constructs and parsing tools are published on www.json.org, in which Org.json and json-lib are relatively simple, but there are some differences in the use of the two. The following first describes an example of how to construct and parse JSON data using
A lot of JSON constructs and parsing tools are published on www.json.org, in which Org.json and json-lib are relatively simple, but there are some differences in the use of the two. The following first describes an example of how to construct and parse JSON data using Json-lib.how to construct and parse
1. Parsing JSON strings Convert the JSON string to a JSON object, and then parse the JSON object:. Jsonobjectjsonobject = Jsonobject.fromobject (JSONSTR);Gets its value based on the key in the JSONStringname = jsonobject.getstring ("name");int age = Jsonobject.getint ("Age"); 2. Converting a
Net.sf.json.JSONObject provides us with a Tobean method for converting to Java objects, which is much more powerful, with the use of the JDK's reflection mechanism as a simple helper tool, some data types need to be converted and scaled as needed. You can handle long and date types here.only supports the processing of a single Jsonobject object, for complex JSON objects, such as jsonarray arrays, consider t
A lot of the JSON construction and parsing tools are published in Java, where Org.json and json-lib are relatively simple, but there are some differences in the use of the two. The following first describes an example of how to construct and parse JSON data using Json-lib.Fi
Conversion between Java objects and collections and Json strings.
To sum up, use the Json jar package to convert Java objects and collections to Json strings:
1. created User class:
package com.ghj.packageofdomain;public class User {private int id;private String name;privat
Import net. sf. json. JSONArray;Import net. sf. json. JSONException;Import net. sf. json. JSONObject;Import net. sf. json. JSONSerializer;/*** Converting a json object to a java object** @ Throws JSONException*/@ TestPublic void j
JSON to transfer such files, as this is already the de facto standard for Web APIs.Not all JSON libraries are called "Clenbuterol". It is important to choose the correct library based on the usage scenario. Hopefully this benchmark will help you.JSON Libraryjson.simple vs Gson vs Jackson vs JSONPWe have selected four main JSON libraries for benchmarking: Json.si
, and Org.json can not directly with the bean conversion and need map as a transit, if the bean to JSON data, first need to convert the bean to M The AP then turns the map into JSON, which is more cumbersome.In short, or that sentence-suitable for their own is the best, we need to choose which method to use to resolve. Finally, we introduce two tools for parsing JSON
JSON string to Java object There are a lot of tools to use, the following small example is just my practicing
Copy Code code as follows:
Import java.util.ArrayList;
Import Java.util.HashMap;
Import java.util.List;
Import Java.util.Map;
Import Com.jfinal.kit.JsonKit;
public class Jsontojavaobject {
public static void Main (string[] args) {Object O1 = Parse ("{\" aa\ ": 123,cc:[1,2,3,4,{
JSON-lib is a Java class package used to convert beans, maps, and XML into JSON and convert JSON back to bean and dynabean.
: Http://json-lib.sourceforge.net/The third-party package is also required:Org. Apache. commons (version 3.2 or later)Org. Apache. oroNet. SF. ezmorph
JSON is a very simple and important data format, which is usually used to exchange and transmit data. It is widely used in JavaScript technology and is becoming increasingly popular in various popular programming languages. There is also a JSON library in Java, which is used to convert Java objects to
JSON, because it is easy to read and write, but also easy to machine parsing and generation, strong compatibility, has become the current server and Web applications between the accepted standard of data transfer. In this article we ran a benchmark test in the Java programming language to test a few common JSON libraries, and see how fast the library is when pars
Various conversion methods (recommended) for processing json in java, javajson
JSON is JavaScript Object Natation. It is a lightweight data exchange format and is very suitable for server-to-JavaScript interaction. This article will quickly explain the JSON format and demonstrate how to process
First, JSON syntaxJson:javascript Object Notation (JavaScript object Notation), JSON is the syntax for storing and exchanging textual information. XML-like, but smaller, faster, and easier to parse than XML.The writing format for JSON data is: name/value pairs.Name/value pairs include the field name (in double quotation marks), followed by a colon, and then the v
JSON plays a big role in data transfer, and the following is how JSON is used in Java.Article reference: http://www.codes51.com/article/detail_99574.htmlJSON string Example[{"id": 1, "name": "Name1", "Password": "Password1", "remark": "Remark1"},{"id": 2, "name": "Name2", "Password": " Password2 "," remark ":" REMARK2 "},{" id ": 3," name ":" Name3 "," Password ":" Password3 "," remark ":" Remark3 "}]Mainly
1. Convert a list of Java objects to a JSON object array and move to a string
Copy Code code as follows:
Jsonarray array = jsonarray.fromobject (userlist);
String jsonstr = array.tostring ();
2. Converts a Java object into a JSON object and converts it to a string
Copy Code code as follo
1.spring MVC returns JSON data and only needs to return a Java Bean object, as long as the Java Bean Object implements serialization Serializeable2.@RequestMapping (value = {"/actor_details"}, Method ={requestmethod.post}) @ResponseBody Publicresultobject actordetails (@RequestBody actordetailsrequest req) {logger.debug ("View {} host information", Req.getaid ())
JS JSON string to JSON object// Convert a JSON-formatted string to a JSON object var t = json.parse (' {' Name ': 123} 'JSON object to JSON string// an array of JSON objects. //Packjso
// create a new JSON array 10 JSONArray jsonArray = new JSONArray (); 11 // create a JSON object 12 JSONObject json1 = new JSONObject (); 13 json1.put ("id", "1"); 14 json1.put ("name", "Zhang San "); 15 json1.put ("password", "123456"); 16 // Add the JSON object to the JSON array to go to 17 jsonArray. add (json1); 1
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.