Read about how to convert xml to json in java, The latest news, videos, and discussion topics about how to convert xml to json in java from alibabacloud.com
Conversion between JSON strings and java objects [json-lib] And jsonjson-lib
During development, data is often exchanged with other systems. The data exchange formats include XML and JSON. JSON, as a lightweight data format, is mo
separated by the ":" Prompt, and the attributes are delimited by ",".
• An array is a collection of sequential values. An array begins with "[", Ends with "]", and the values are separated by ",".
• The value can be a string, number, true, false, NULL, or an object or array in quotation marks. These structures can be nested.
• The definition of a string is basically consistent with C or
value can be a string, number, true, false, NULL, or an object or array in quotation marks. These structures can be nested.
• The definition of a string is basically consistent with C or Java.
• The definition of numbers is also basically consistent with C or Java.
JSON VS XML
• readability
) {this.name = name;}}Case 1: Demonstrating the generation of XML format data:Xstream.useattributefor (Province.class, "id"); This sentence means to take the ID as a property of province.Xstream.alias ("province", Province.class), which means to convert Package App.xstream;import Java.util.arraylist;import Java.util.list;import com.thoughtworks.xstream.XStream; public class Xstreamdemo {public static void m
The struts configuration is as follows:
Models is a list set of queries. Data has been received in the flex foreground,
Turn left | turn right
Other data can be displayed normally, but only the date type does not know how to display it.
Turn left | turn right
The date in the database is:
Turn left | turn right
Turn left | turn right
The field indicates:
Year: year (when converting to XML format, it is to subtract the cur
1. The first method uses JSON-java provides a method that has been used before json-Lib provides a way to JSON, later discovered this open source project, found that it is very good to use, and can modify the parse method in the Xml.java to meet their own conversion needs. (1first go to git to download the required
1. Introduction to the definition
1.1 XML definition
The Extensible Markup Language (extensible Markup Language, XML), which is used to mark an electronic file with a structured markup language, can be used to mark data, define data types, and is a source language that allows users to define their own markup language. XML organizes data using the DTD (document
, C + +, C #, Java, JavaScript, Perl, Python, etc.). These features make JSON an ideal data exchange language.JSON is constructed in two structures:A collection of name/value pairs (A collection of name/value pairs). In different languages, it is understood as objects (object), record (record), structure (struct), Dictionary (dictionary), hash table (hash table), keyed list (keyed list), or associative arra
Using Gson to convert a map to JSONGson (also known as Google Gson) is an open-source Java library published by Google, which uses either a serialized Java object as a JSON string or a drag-formatted JSON string as a Java object.
1. Introduction to the definition
(1). XML definition
The Extensible Markup Language (extensible Markup Language, XML), which is used to mark an electronic file with a structured markup language, can be used to mark data, define data types, and is a source language that allows users to define their own markup language. XML organizes data using the DTD (document
Xml,object,json An analysis of transformation Xstream the UsePlease respect other people's labor results, reproduced please specify the source: Analysis of the Xml,object,json conversion XStream useXStream is a simple library that is used primarily for Java objects, and
Do javaweb development of the most commonly used a thing El expression, this thing is a very useful thing, but sometimes we deal with complex string manipulation, it is a little bit, this time we need to use a custom method to achieve more concise and convenient things.The following custom El expression that turns an object into a JSON string is used to illustrate this custom process:Elfunctions.javaimport net.sf.json.JSONObject;publicclass ElFunction
Do javaweb development of the most commonly used a thing El expression, this thing is a very useful thing, but sometimes we deal with complex string manipulation, it is a little bit, this time we need to use a custom method to achieve more concise and convenient things.The following custom El expression that turns an object into a JSON string is used to illustrate this custom process:Elfunctions.javaimport net.sf.json.JSONObject;publicclass ElFunction
convenient.Disadvantages:(1) The XML file is large, the file format is complex, the transmission occupies the bandwidth;(2) Both the server side and the client need to spend a lot of code to parse the XML, causing the server and client code to become unusually complex and difficult to maintain;(3) The client is inconsistent in parsing XML between different brows
{ //Create XML Document object, save path to e:\\test.xml file File=new file ("D:\\test.xml"); Declaring Jaxbcontext Context objects Jaxbcontext context=jaxbcontext.newinstance (article.class); Creates a Java object that is converted to XML through a context object Marshaller; Marshaller M=context.createmarshaller ();
:/book/published/year/text (). However, there must be an XPath processor that parses the request and returns 2004. Fortunately, XPath2.0 is a powerful retrieval engine integrating functions, predicates, and axes. without Java code writing any traversal logic, you can add any logic in the form of a natural language in the XPath request. for example, you can directly send the request "How many books were published by David West in 2004?" You can get the
to load the string of the JavaScript Object declared in the background at the front end, convert it to the actual object using the eval method, and update the page information through DHTML.
JSON format
The basic JSON format is as follows:An object is a set of attributes and value pairs. An object starts with "{" and ends "}". Each attribute name and value is
execute an expression in a JSON string.4.JSON Official Conversion Mode :http://www.json.org/provides a json.js so that IE8 (compatibility mode), IE7 and IE6 can support JSON objects as well as their stringify () and Parse () methods;Can get this JS on Https://github.com/douglascrockford/JSON-js, generally now use json
1. Definition Introduction(1). XML definitionThe Extensible Markup Language (extensible Markup Language, XML), which is used to tag electronic files with a structured markup language that can be used to tag data, define data types, is a source language that allows users to define their own markup language. XML uses the DTD (document type definition) document type
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.