(string JSON, String selector) {jsonobject Jo = null; Jsonarray ja = null; String jsontext = ""; String item = ""; String flag = "O"; O-jsonobject; A-jsonarray; T-text// Arguments must not is null if (JSON = = NULL | | selector = = NULL) {This.message = "The argument {" + JS On + "} and {" + selector + "} must is not NULL, please check this!"; T
Fastjson is a very good Java language implementation of the JSON parser and generator, from the Alibaba engineer Development.
Main Features:
Quick Fast (faster than any other java-based parser and generator, including Jackson)
• Strong (support for common JDK classes including any Java Bean class, Collection, Map, d
A good example of the mutual transfer of Java objects and JSON objects:1 Packagecom.kenneth.test;2 3 Importjava.util.ArrayList;4 Importjava.util.Collection;5 ImportJava.util.Iterator;6 Importjava.util.List;7 8 ImportNet.sf.json.JSONArray;9 ImportNet.sf.json.JSONObject;Ten One /** A * Created by Administrator on 2016/2/1 0001. - */ - Public classJsonandjava { the - Public Static voidMain (string[]
The Recent use of Java to manipulate JSON data, although JSON used a few times, but has not been well summarized, while this time to summarize the Java operation JSON data. Java operation JSO
The Recent use of Java to manipulate JSON data, although JSON used a few times, but has not been well summarized, while this time to summarize the Java operation JSON data. Java operation JSO
About converting Jsonobject to JavaBean, in fact, there is a Tobean () method in Jsonobject to deal with, also can be based on a given jsonconfig to deal with the corresponding requirements, such as filtering the specified properties[Java]View PlainCopyPrint?
//Returns TRUE to filter out the attribute
Jsonconfig.setjsonpropertyfilter (new propertyfilter () {
@Override
Public boolean apply (object o, String N, Object v) {
return fal
1. Convert the JSON string to a Java object Jsonobject obj = new Jsonobject (). Fromobject (JSONSTR);//Convert the JSON string to a JSON object person jb = (person) jsonobject. Tobean (obj,person.class);//Convert a JSON object to a Person object2. Convert a
=jobj.getjsonobject (jdate); =datalist.getstring (name); return balance; 5. Get the JSON containing the nth JSON in the array, such as {"A", "1", "B", "[{" A2 "," 1 "},{" B2 "," 1 "}]"} /* Get Jsonarray */ Public Static int index) { = jsonobject.fromobject (JSON); Jsonarray Childs= Jobj.getjso
\": \ "marry\", \ "age\": \ "18\"} "+
"]} ";
Gson Gson = new Gson ();
Gsondataanalysis Gda = Gson.fromjson (
stotalstring, gsondataanalysis.class);
for (int i = 0; i system.out.print ("Name:" + gda.getlist (). get (i). GetName () + "");
System.out.println ("Age:" + gda.getlist (). get (i). Getage ());
Note: When using the Gson class, add the Gson.jar package to the project.
Here to introduce Java parsing JS
JSON serialization: Converts a Java bean into a JSON string; JSON deserialization: Converts a JSON string into a Java bean.
XML serialization: Converting Java beans to XML files; XML de
Automatically generate model classes based on JSONJavaConvert JSON to Java class http://jsongen.byingtondesign.com you bring the JSON, we'll bring the codeFind a great site that can directly generate a JSON string into the Java model class, super convenient. Long ago knew, h
;ImportJava.io.PrintWriter;Importjava.util.ArrayList;Importjava.util.List;Importjavax.servlet.ServletException;ImportJavax.servlet.http.HttpServlet;Importjavax.servlet.http.HttpServletRequest;ImportJavax.servlet.http.HttpServletResponse;ImportNet.sf.json.JSONArray; Public classTestjsonextendsHttpServlet { Public voiddoget (httpservletrequest request, httpservletresponse response)throwsservletexception, IOException {doPost (request,response); } Public voidDoPost (httpservletrequest request, h
= [jsonStr objectFromJSONString];BMClass* c = [[BMClass alloc]initWithDictionary:dic];
The results of the parsed after operation are as follows (Debug): Nsarray-type JSON string conversion to an objectIf you get a string that is not of type "{}", but "[]" type, then the above parsing method does not apply, you need tonsdictionary* dic = [Jsonstr objectfromjsonstring];Revision changed tonsarray* array = [Jsonstr objectfromjsonstring];The o
A. JSON understanding
1.json (JavaScript Object notation): JavaScript Object notation, which uses the syntax of JavaScript objects to represent object data, is a format for storing and transferring data, and its advantages are easy to read, easy to parse, It has the advantage of being smaller, faster, and easier to parse than traditional XML. -See also the two for more details. How to generate
JSON Goto XMLExt: 24804337XMLSerializer xmlserial = new XMLSerializer ();Jsonarray jsonobject = Jsonarray.fromobject (obj.tostring ());String XML = Xmlserial.write (Jsonobject);Note: Using XmlSerializer requires the introduction of XMO jar packages, Xom-1.2.10.jarOtherwise it will error: Java.lang.noclassdeffounderror:nu/xom/parentnode2.XML Turn JSONExt: 53291994XMLSerializer XMLSerializer = new XMLSerializer ();String
1. The list collection is converted into JSON codeList List = new ArrayList ();List.add ("first");List.add ("second");Jsonarray jsonArray2 = jsonarray.fromobject (list);2. Map collection into JSON codeMap map = new HashMap ();Map.put ("name", "JSON");Map.put ("bool", boolean.true);Map.put ("int", new Integer (1));Map.put ("arr", new string[] {"A", "B"});Map.put (
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.