There are many tools that can be used to convert json string to Java object. The following small example is just my practice
import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import com.jfinal.kit.JsonKit; public class JsonToJavaObject { public static void main(String[] args) { Object o1 = parse("{\"aa\":123,cc:[1,2,3,4,{cd:f,bb:234}]}"); System.out.println(JsonKit.toJson(o1)); } public static Object parse(String json){ if(json == null){ return null; } json = json.trim(); if("string".equals(typeof(json))){ return json; } if("map".equals(typeof(json))){ return parseMap(json); } if("list".equals(typeof(json))){ return parseList(json); } return null; } public static Map parseMap(String json){ if(!"map".equals(typeof(json))){ throw new RuntimeException("json 不是Map类型"); } Map r = new HashMap(); parseToken(r,json,null); return r; } public static List parseList(String json){ if(!"list".equals(typeof(json))){ throw new RuntimeException("json 不是list类型"); } List r = new ArrayList(); parseToken(null, json, r); return r; } public static String typeof(String json){ if(json.length() == 0)return "string"; if('{'==json.charAt(0)){ if('}' == json.charAt(json.length()-1)){ return "map"; } } if('['==json.charAt(0)){ if(']'==json.charAt(json.length()-1)){ return "list"; } } return "string"; } private static void parseToken(Map r, String json,List r2) { boolean syh = true; //双引号 boolean dyh = true;//单引号 boolean dkh = true;//大括号 boolean zkh = true;//中括号 boolean isKey = true; StringBuffer key = new StringBuffer(); StringBuffer value = new StringBuffer(); for(int i=1;i<json.length()-1;i++){ char item = json.charAt(i); if(dyh&&syh&&zkh)if('{' == item || '}' == item){ dkh = !dkh; } if(dyh&&syh&&dkh)if('[' == item || ']' == item){ zkh = !zkh; } if(dyh&&dkh&&zkh)if('"' == item){ syh = !syh; continue; } if(syh&&dkh&&zkh)if(syh)if('\'' == item){ dyh = !dyh; continue; } if(dyh&&syh&&dkh&&zkh)if(r2==null)if(dyh)if(':'==item){ isKey = false; continue; } if(dyh&&syh&&dkh&&zkh)if(','==item){ isKey = true; if(r != null){ r.put(key.toString(), parse(value.toString())); } if(r2 != null){ r2.add(parse(key.toString())); } key = new StringBuffer(); value = new StringBuffer(); continue; } if(isKey){ key.append(item); }else{ value.append(item); } } if(!key.toString().trim().equals("")){ if(r != null){ if(value.toString().trim().equals(""))throw new RuntimeException("json 格式错误"); r.put(key.toString(), parse(value.toString())); } if(r2 != null){ r2.add(parse(key.toString())); } } } }
Console output
{"aa":"123","cc":["1","2","3","4",{"bb":"234","cd":"f"}]}
More json to java object examples related articles Please pay attention to PHP Chinese website!

This article analyzes the top four JavaScript frameworks (React, Angular, Vue, Svelte) in 2025, comparing their performance, scalability, and future prospects. While all remain dominant due to strong communities and ecosystems, their relative popul

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

This article addresses the CVE-2022-1471 vulnerability in SnakeYAML, a critical flaw allowing remote code execution. It details how upgrading Spring Boot applications to SnakeYAML 1.33 or later mitigates this risk, emphasizing that dependency updat

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

Node.js 20 significantly enhances performance via V8 engine improvements, notably faster garbage collection and I/O. New features include better WebAssembly support and refined debugging tools, boosting developer productivity and application speed.

Iceberg, an open table format for large analytical datasets, improves data lake performance and scalability. It addresses limitations of Parquet/ORC through internal metadata management, enabling efficient schema evolution, time travel, concurrent w

This article explores integrating functional programming into Java using lambda expressions, Streams API, method references, and Optional. It highlights benefits like improved code readability and maintainability through conciseness and immutability

This article explores methods for sharing data between Cucumber steps, comparing scenario context, global variables, argument passing, and data structures. It emphasizes best practices for maintainability, including concise context use, descriptive


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

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

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

Dreamweaver Mac version
Visual web development tools

Notepad++7.3.1
Easy-to-use and free code editor

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