search
HomeJavajavaTutorialWhat package does java use to parse json?

Toolkitorg.json.jar is a lightweight json construction and parsing toolkit under JAVA. It also includes conversion of JSON to XML, HTTP headers, Cookies, and CDL.

Recommended here: Alibaba FastJson is a Json processing toolkit, including "serialization" and "deserialization". It has the following characteristics:
Fastest speed, testing It shows that fastjson has extremely fast performance, surpassing any other Java Json parser. Including JackJson, which claims to be the fastest;

Recommended courses: Java Tutorial.

What package does java use to parse json?

is powerful and fully supports Java Beans, collections, Maps, dates, Enums, supports paradigms, and supports introspection; has no dependencies and can run directly on Java SE 5.0 or above. ;Support Android; Open source (Apache 2.0)

Source code address:

https://github.com/alibaba/fastjson

The Fastjson API entry class is com.alibaba.fastjson.JSON. Common serialization operations can be completed directly through static methods on the JSON class.

public static final Object parse(String text); // Parse JSON text into JSONObject or JSONArray
public static final JSONObject parseObject(String text); // Parse JSON text into JSONObject
public static final T parseObject(String text, Class clazz); // Parse JSON text into JavaBean
public static final JSONArray parseArray(String text); // Parse JSON text into JSONArray
public static final List parseArray (String text, Class clazz); //Parse JSON text into a JavaBean collection
public static final String toJSONString(Object object); //Serialize JavaBean into JSON text
public static final String toJSONString(Object object , boolean prettyFormat); // Serialize JavaBean into formatted JSON text
public static final Object toJSON(Object javaObject); Convert JavaBean to JSONObject or JSONArray.

The above are common methods in some projects.

The following is the code I wrote for practice:

package com.test;
 
public class TestPerson {
    private int age;
    private String name;
     
    public TestPerson(){
         
    }
     
    public TestPerson(int age,String name){
        this.age=age;
        this.name=name;
    }
     
    public int getAge() {
        return age;
    }
    public void setAge(int age) {
        this.age = age;
    }
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
}
 
 
 
package com.test;
import java.util.*;
 
import com.alibaba.fastjson.*;
 
public final class TestFastJson {
 
    public static void main(String[] args) {
        // TODO Auto-generated method stub
         
        TestPerson json = new TestPerson(19,"李明");
        List<testperson> list = new ArrayList<testperson>();
        list.add(json);
        list.add(new TestPerson(12,"张三"));
        //将集合或者对象序例化成JSON
        System.out.println(JSON.toJSON(json));
        System.out.println( JSON.toJSON(list) );
        //Json串反序列化成对象
        TestPerson person = JSON.parseObject("{\"name\":\"李明\",\"age\":19}", TestPerson.class);
        System.out.printf("name:%s,age:%d\n",person.getName(),person.getAge());
         
        String str = "[{\"name\":\"李明\",\"age\":19},{\"name\":\"张三\",\"age\":12}]";
        //数组对象反序列化成集合
        List<testperson> listPerson = JSON.parseArray(str,TestPerson.class);
         
        for(TestPerson item : listPerson){
            System.out.println( item.getName() );
            System.out.println( item.getAge());
        }
         
        //没有对象直接解析JSON对象
        JSONObject jobj = JSON.parseObject("{\"name\":\"李明\",\"age\":19}");
        System.out.printf("name:%s,age:%d\n",jobj.getString("name"),jobj.getBigInteger("age"));
         
        //没有对象直接解析JSON数组
        JSONArray jarr = JSON.parseArray("[{\"name\":\"李明\",\"age\":19},{\"name\":\"张三\",\"age\":12}]");
         
        for(int i=0,len=jarr.size();i<len></len></testperson></testperson></testperson>

The above is the detailed content of What package does java use to parse json?. For more information, please follow other related articles on the PHP Chinese website!

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
How do I use Maven or Gradle for advanced Java project management, build automation, and dependency resolution?How do I use Maven or Gradle for advanced Java project management, build automation, and dependency resolution?Mar 17, 2025 pm 05:46 PM

The article discusses using Maven and Gradle for Java project management, build automation, and dependency resolution, comparing their approaches and optimization strategies.

How do I create and use custom Java libraries (JAR files) with proper versioning and dependency management?How do I create and use custom Java libraries (JAR files) with proper versioning and dependency management?Mar 17, 2025 pm 05:45 PM

The article discusses creating and using custom Java libraries (JAR files) with proper versioning and dependency management, using tools like Maven and Gradle.

How do I implement multi-level caching in Java applications using libraries like Caffeine or Guava Cache?How do I implement multi-level caching in Java applications using libraries like Caffeine or Guava Cache?Mar 17, 2025 pm 05:44 PM

The article discusses implementing multi-level caching in Java using Caffeine and Guava Cache to enhance application performance. It covers setup, integration, and performance benefits, along with configuration and eviction policy management best pra

How can I use JPA (Java Persistence API) for object-relational mapping with advanced features like caching and lazy loading?How can I use JPA (Java Persistence API) for object-relational mapping with advanced features like caching and lazy loading?Mar 17, 2025 pm 05:43 PM

The article discusses using JPA for object-relational mapping with advanced features like caching and lazy loading. It covers setup, entity mapping, and best practices for optimizing performance while highlighting potential pitfalls.[159 characters]

How does Java's classloading mechanism work, including different classloaders and their delegation models?How does Java's classloading mechanism work, including different classloaders and their delegation models?Mar 17, 2025 pm 05:35 PM

Java's classloading involves loading, linking, and initializing classes using a hierarchical system with Bootstrap, Extension, and Application classloaders. The parent delegation model ensures core classes are loaded first, affecting custom class loa

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Chat Commands and How to Use Them
1 months agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Atom editor mac version download

Atom editor mac version download

The most popular open source editor