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
(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
the database2String Jsonattribute = This. getattribute ();3 //convert to JSON array4Jsonarray jsonattr =Jsonarray.fromobject (jsonattribute);5 //because the attribute class contains List6mapNewHashmap(); 7Classmap.put ("Attributevalues", AttributeValue.class); 8 //Final Convert List object complete9Listclass, Classmap);Another way to deal with the data, this will be more simple, the operation of the database more convenient, but in the database is no
. Action MethodRegistered Address: District-town public void Qu2zhen () {listThe above code is relatively simple, in the method received from the front desk .ID, and then callServicemethod to get theIDunder the allListentity Collection, and then theListset Conversion toJSON, we will alsoJsonprinted out. Here'sJsontransformation is the last article, the expansion of the introduction of theListthe collection is transformed intoJSONthe method for the object. SummaryThis will take advantage Ajax +
First step: Create a new Jsonbinder.java class with the following code:
Import java.io.IOException;
Import Java.text.DateFormat;
Import Java.text.SimpleDateFormat;
Import Java.util.HashMap;
Import Java.util.Map;
Import Org.apache.log4j.LogManager;
Import Org.apache.log4j.Logger;
Import Org.codehaus.jackson.map.DeserializationConfig;
Import Org.codehaus.jackson.map.ObjectMapper;
Import org.codehaus.jackson.map.annotate.JsonSerialize;
Import Org.springframework.util.StringUtils;
public class J
When docking with a third party, the JSON time parameter fields that are returned to us are very common, so it's certainly going to take a while for us to create javabean manually, so we can use JSON to automatically generate JavaBean tools, here's a brief introduction to IntelliJ idea Plug-in Gsonformat in the.1. What is GsonformatConverts the JSON data format i
Classes to use: Net.sf.json.JSONObject
When using JSON, In addition to importing the Json-lib-2.2-jdk15.jar packages downloaded above the JSON Web site, you must have several other dependent packages: Commons-beanutils.jar,commons-httpclient.jar,commons-lang.jar,ezmor Ph.jar,morph-1.0.1.jar
Here is the example code:
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
This article introduces how to implement data paging display based on jquery + ajax + json and asynchronous paging Based on JAVA + JQuery. The code in this article is easy to understand and has reference value, if you are interested in learning together, let's show you how to run:
1. The background action generates json data.
List blackList = blackService. getB
Building a JSON web service with Java and axis2january 23rd, 2009 ·
9 comments
It is said that in Java usually the easiest things are the hardest. The following is a nice example as it took me some time to figure out how to do it.I wanted to build a simple URL request based Web Service in Java that returns an
Use the Net.sf.json package to convert the XML string to Jsonobject:Introducing Maven Dependencies:Dependency> groupId>Net.sf.json-libgroupId> Artifactid>Json-libArtifactid> version>2.2.2version> classifier>Jdk15classifier>Dependency>Java code:Import Net.sf.json.xml.XMLSerializer; Import Net.sf.json.JSONArray; Import Net.sf.json.JSONObject; { ... String XML; // assumed to be an
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.