Home IT Linux Windows Database Network Programming Server Mobile  
           
  Home \ Programming \ Json Applications of FastJson     - 11 you Linux Terminal Command (Linux)

- FPM quickly create packages with RPM (Linux)

- Linux system package manager -RPM (Linux)

- Java Foundation - The relationship between abstract classes and interfaces (Programming)

- The FreeBSD zfs: failed with error 6 Error Resolution (Linux)

- Ubuntu 32 compile Android 4.0.4 Problems (Linux)

- Create a custom pixel format based on an existing image data BufferedImage (Programming)

- Linux Shell Scripting multithreading (Programming)

- Tomcat configuration memory and remote debug port (Server)

- cp: omitting directory error solutions under Linux (Linux)

- Linux foundation tutorial: how to modify the host name on CentOS or RHEL 7 (Linux)

- in no backup ex: error: Xin Tourou ah backup child process has Singles DAT / US person / bin / in no backup ex (Database)

- Linux kernel compilation, the configuration of the motor drive (Programming)

- Linux atomic operations and synchronization mechanisms (Programming)

- Java Virtual Machine Basics (Programming)

- Use mysqldump backup performed MariaDB (Database)

- Mac OS X 10.9 compiler OCI8 module (Programming)

- Security experience: to see how the experts deal with DDoS attacks (Linux)

- Java learning problems encountered (Programming)

- How to use Linux iptables tool for network sharing (Linux)

 
         
  Json Applications of FastJson
     
  Add Date : 2017-04-04      
         
       
         
  These days the Internet to find some cases of about Json, unintentionally I found a good personal feeling is that Alibaba engineers to write FastJson.

package com.jerehedu.fastjson;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Vector;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.serializer.SerializerFeature;
import com.jerehedu.entity.Userinfo;

/ **
 * Fastjson is a very good performance of Java language implementation of JSON parser and generator, engineers have developed from Alibaba. main feature:
 * 1. Fast FAST (than any other Java-based parser and generator faster, including jackson) strong (JDK support the general category includes any Java Bean
 * 2.Class, Collection, Map, Date, or enum) zero-dependent (not dependent on any other library in addition to JDK)
 *
 * /
public class TestFastJson {

    public static void main (String [] args) {
        String json = "{\" name \ ": \" chenggang \ ", \" age \ ": 24}";
        String arrayAyy = "[[\ 'Ma', 50], null, [\ 'Ma', 30]]";
        Entity2json ( "zhangsan", 24);
        list2Json ();
        Complexdata ();
        Deserialization (json);
        DateFormate (new Date ());
        Json2Eetity (json);
        String2JSONArray (arrayAyy);
    }

    // Entity into Json
    public static void Entity2json (String name, int age) {
        Userinfo info = new Userinfo (name, age);
        String str_json = JSON.toJSONString (info); //
        System.out.println ( "entity into Json" + str_json);
    }

Directly to our physical transformation for Json format.

    // List turn Json
    public static void list2Json () {
        List < Userinfo> list = new ArrayList < Userinfo> ();
        Userinfo userinfo1 = new Userinfo ( "lisi", 15);
        Userinfo userinfo2 = new Userinfo ( "wangwu", 16);
        list.add (userinfo1);
        list.add (userinfo2);
        String json = JSON.toJSONString (list, true);
        System.out.println ( "List collection turn json format string:" + json);
    }
 
      // Array of characters into JSon
    private static void String2JSONArray (String arrayAyy) {
        JSONArray array = JSONArray.parseArray (arrayAyy);
        System.out.println ( "Array:" + array);
        System.out.println ( "array length:" + array.size ());
        Collection nuCon = new Vector ();
        nuCon.add (null);
        array.removeAll (nuCon);
        System.out.println ( "Array:" + array);
        System.out.println ( "array length:" + array.size ());
    }

 // Complex data types
    public static void Complexdata () {
        HashMap < String, Object> map = new HashMap < String, Object> ();
        map.put ( "username", "zhangsan");
        map.put ( "age", 24);
        map.put ( "sex", "M");



        // Map collection
        HashMap < String, Object> temp = new HashMap < String, Object> ();
        temp.put ( "name", "xiaohong");
        temp.put ( "age", "23");
        map.put ( "girlInfo", temp);

        // List collection
        List < String> list = new ArrayList < String> ();
        list.add ( "mountain");
        list.add ( "rider");
        list.add ( "Travel");
        map.put ( "hobby", list);
        String jsonString = JSON.toJSONString (map);
        System.out.println ( "complex data types:" + jsonString);
    }
 
Operating results as follows:

Complex data types: { "age": 24, "girlInfo": { "age": "23", "name": "xiaohong"}, "hobby": [ "climbing", "cycling", "tourism" ], "sex": "M", "username": "zhangsan"}

    public static void Deserialization (String json) {
        Userinfo userInfo = JSON.parseObject (json, Userinfo.class);
        System.out.println ( "The name is:" + userInfo.getName () + ", the age is:"
                + UserInfo.getAge ());
    }

// If the date format
    public static void DateFormate (Date date) {
        System.out.println ( "output milliseconds:" + JSON.toJSONString (date));
        System.out.println ( "The default format is:"
                + JSON.toJSONString (date,
                        SerializerFeature.WriteDateUseDateFormat));
        System.out.println ( "Custom Date:"
                + JSON.toJSONStringWithDateFormat (date, "yyyy-MM-dd",
                        SerializerFeature.WriteDateUseDateFormat));
    }

// Json into entities
    private static void Json2Eetity (String json) {
        Userinfo userInfo = JSON.parseObject (json, Userinfo.class);
        System.out.println ( "address output object:" + userInfo.toString ());
        System.out.println ( "output object name:" + userInfo.getName ());
    }
}

FastJson still relatively easy to use a parsing format, whether it is converted to Json, or parse Json. Github address https://github.com/AlibabaTech/fastjson.
     
         
       
         
  More:      
 
- Ora-00020: maximum number of processes (500) exceeded (Database)
- Safety testing Unix and Linux server entry succinctly (Linux)
- Oracle ordinary users show parameter method (Database)
- Various sorting algorithms implemented in Python (Programming)
- Btrfs file system repair techniques (Linux)
- Two kinds of agents of Spring AOP (Programming)
- Additional SQL Server 5123 database reported error (Database)
- Quickly locate the mistakes by gdb location (Programming)
- About redis in Replication (Database)
- To compile and install Redis Linux and master-slave replication configuration (Database)
- Monitor traffic Linux Shell Edition (Programming)
- How to install and configure the KVM and Open vSwitch on Linux distributions (Linux)
- Installation under Linux to deploy Java (Linux)
- Grading defense against Linux server attacks (Linux)
- Spring Data study notes -Helloworld (Programming)
- Use OpenSSL carried BASE64 encoding and decoding (Linux)
- Struts2 configure a static resource files without Struts processing (regular match) (Programming)
- MySQL various log summary (Database)
- Linux performance monitoring (Linux)
- Linux system firewall defense network attacks (Linux)
     
           
     
  CopyRight 2002-2016 newfreesoft.com, All Rights Reserved.