Free Shipping on orders over US$39.99 How to make these links

Using JSON data exchange format to realize the design of data exchange framework

With the development of wireless technology and the popularization of wireless communication devices, wireless mobile applications based on small consumer and embedded devices such as mobile phones and PDAs are becoming more and more extensive. Among programmable mobile phones, Java-based mobile phones are the most popular. In fact, Java has been accepted by most mobile phone manufacturers as the standard for mobile phone applications and services.

Authors: Hu Wenfa, Bai Zhongying

1 Introduction

With the development of wireless technology and the popularization of wireless communication devices, wireless mobile applications based on small consumer and embedded devices such as mobile phones and PDAs are becoming more and more extensive. Among programmable mobile phones, Java-based mobile phones are the most popular. In fact, Java has been accepted by most mobile phone manufacturers as the standard for mobile phone applications and services. Choosing the right data exchange format is an important design decision when building network-aware software, especially when designing mobile and embedded applications, where features such as light weight and efficiency are important characteristics to consider. Such features are important because they translate into lower computing requirements and power usage, better performance, and lower operating costs. This paper studies the advantages of JSON data exchange format compared with XML and traditional data exchange formats, and proposes a general implementation framework of JSON data exchange format between client (J2ME) and server (J2EE).

2 Introduction to J2ME/J2EE

J2ME (Java 2 Platform. MICRO Edition) is part of Java 2. Porting the platform-independent features of the Java language to small Electronic devices, allowing applications to be shared among mobile wireless devices. J2ME is a technology for application development for limited hardware, limited power, and limited network connection devices, and is suitable for developing network applications with strong interactivity on unlimited communication devices. The MIDP application program written on this basis has good compatibility and portability, and can run well on handheld devices such as PDA.

J2EE, the enterprise edition of the Java 2 platform, is an architecture that simplifies enterprise solutions using the Java 2 platform. J2EE uses a multi-layer distributed application model, and its typical 4-layer structure is: ① Client-level components running on client machines, such as Web browsers, Java Applets, etc.; ② Web-level components running on J2EE servers, such as Servlet and JSP; ③ business logic layer component (EJB) running on J2EE server; ④ enterprise information system layer software running on EJS (Enterprise Information System) server.

3 Introduction to JSON

JSON (JavaScript. Object Noation) is a lightweight data interchange format that is easy to read and write, and easy to parse and generate by machines. JSON is in a completely language-independent text format, but also uses conventions similar to the C language family. These properties make JSON an ideal data interchange language.

There are two types of data in JSON format: object and array. An object is an unordered collection of name/value pairs. An object starts with “{” and ends with “}”. Each “name” is followed by a “:”; name/value pairs are separated by “,”. An ordered combination of array values ​​(value). An array starts with “{” and ends with “}”. Use “,” to separate the values.

4 Data Exchange Format Analysis

XML is a language used to describe the information storage format. Its advantages are strong robustness and descriptiveness, and it is the communication data format selected by the new generation of open and interoperable Web Services. In mobile applications, developers often create their own data interchange format or extensible markup language XML. The former has the advantage that it can be tuned for specific situations to maximize performance and maximize the use of computing resources. The advantage when using the latter over HTTP is that it is the de facto standard for data exchange. Also, the text-based representation used in XML makes it easy to debug. Both approaches have their drawbacks, the former being inherently proprietary, non-standard, and potentially non-interoperable, while the latter data representation is too formal and cumbersome, especially for mobile and embedded applications.

JSON is a lightweight data interchange format that is text-based, readable and easy to debug. JSON supports the representation of all basic data types and provides methods for parsing these data types to each other into Java types. For lightweight applications, the JSON data exchange format can better save the computing resources of mobile phones, reduce network transmission time, and speed up network transmission.

5 Data exchange framework implementation

5.1 Overall design of the frame

The framework consists of two parts: J2ME client and J2EE server. The client uses the MIDP technology of J2ME, and the server uses the servlet technology of J2EE. The client uses the HTTP protocol to send the serialized JSON message to the server. The server deserializes the JSON message, performs the corresponding operation according to the client request, and serializes the result of the request into a JSON message and returns it to the client. After obtaining the returned JSON message, deserialize it into the specific required data. Figure 1 shows the overall design framework.

Using JSON data exchange format to realize the design of data exchange framework

5.2 Server side

The server side uses serverlet to receive the JSON message based on the HTTP protocol sent by the client, and calls the JSONObject class to deserialize the JSON to obtain the required detailed information. According to the data type of JSON format, the data in JSON format needs to be deserialized in three situations: ① Simple object form. Implementation method: Create a JSONObiect instance, and then call the getString() function. The specific form is as follows: JSONObject jsonObj=newJSONObject(message); String title=jsonObj.getString(“title”); where message is the received JSON message, and title represents The name you want to get. ②The form of nested objects inside the object. Implementation method: call its getJSONObject() method on the basis of the original object. The specific form is as follows: JSONObjectbody_obj=jsonObj.getJSONObject(); ③Array form. Implementation method: call getJSONArray() on the basis of the original object to get an array of data type JSONOobject. After the detailed information of the request is obtained by deserialization, the J2EE side performs other operations according to the request, such as obtaining XML data from the network, obtaining data from the database, and so on. After getting the data, the server serializes the data into a JSON format message and sends it to the client.

5.3 Client

The client sends the serialized JSON format message to the server, then waits for the message returned by the server, and deserializes the JSON message after receiving the message returned by the server. The process calls the API of ison.me. The specific implementation is as follows: ① Serialize into JSON format. Just call JSONObjeet’s put method to add related items. JSONObject can add 3 kinds of objects: simple objects, JSONObject objects, JSONArray objects. The specific operations are as follows: JSONObject header=new JSONObjeet(); headerput(“title”, “yahoonews”); JSONObject childObj=new JSONObject(); header.put(“child”, childObj); JSONArray arrayObj=new JSONArray(); headerput(“array”, arrayObj); ② Deserialize messages in JSON format. Deserialization also includes three cases: simple JSONObject objects, nested JSONObject objects, and array objects. The specific implementation is as follows: JSONObject bj=new JSONObject(str); String title=obj-getString(“title”); intcount=obj.getInt(“count”); JSONObject body=obj.getJSONObject(“body”); JSONArray arrayObj =obj.getJSONArray(“array”);

5.4 Transport Protocol Layer

The communication between the client and the server uses the HTTP protocol. HTTP protocol is a widely used protocol, all MIDP devices support HTTP protocol. And on various wireless networks, the HTTP protocol is relatively easy to implement. There are two HTTP protocol request methods: GET and POST. There is a limit to the URL string length when sending large chunks of data due to GET requests. Object JSON strings can be very long, especially when working with extremely complex objects.

At the same time, in the cross-domain network, all data is sent in plain text, and the security is difficult to guarantee. Therefore, it is recommended to use POST to send confidential or extremely long requests.

6 Conclusion

By analyzing JSON, XML and custom data exchange format, JSON is proposed as a lightweight data exchange format, and a general framework of its client (J2ME) and server (J2EE) solutions is given, which solves the problem of custom and The tedious and resource-consuming defects brought by the use of XML data interchange format.

The Links:   SKM50GB063D DMC-40457-NY-LY-B-CKN

We will be happy to hear your thoughts

Leave a reply

House idea
Logo
Enable registration in settings - general
Compare items
  • Total (0)
Compare
0
Shopping cart