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.
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!

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

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

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

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]

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


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

WebStorm Mac version
Useful JavaScript development tools

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

SublimeText3 Chinese version
Chinese version, very easy to use

Atom editor mac version download
The most popular open source editor