随笔 - 832  文章 - 2  评论 - 31  阅读 - 167万

JSONObject没有fromObject方法及其依赖引入

原因是导包导错了,需要的是下面这个包:

import net.sf.json.JSONObject;

 

而不是其他的包:

 

import com.alibaba.fastjson.JSONObject;

一、开发场景

Java开发当中经常需要Json格式的数据,这就用到JSONObject类,本文章只提供以下两种JSONObject对应架包的下载方式。
1、com.alibaba.fastjson.JSONObject(依赖1个架包fastjson-1.2.28.jar)
2、net.sf.json.JSONObject
(依赖6个架包commons-beanutils-1.9.3.jar、commons-collections-3.2.1.jar、commons-lang-2.6.jar、commons-logging-1.1.1.jar、ezmorph-1.0.6.jar、json-lib-2.4-jdk15.jar)
net.sf.json.JSONObject依赖

复制代码
<!-- JSONObject对象依赖的jar包 -->  
        <dependency>  
            <groupId>commons-beanutils</groupId>  
            <artifactId>commons-beanutils</artifactId>  
            <version>1.9.3</version>  
        </dependency>  
        <dependency>  
            <groupId>commons-collections</groupId>  
            <artifactId>commons-collections</artifactId>  
            <version>3.2.1</version>  
        </dependency>  
        <dependency>  
            <groupId>commons-lang</groupId>  
            <artifactId>commons-lang</artifactId>  
            <version>2.6</version>  
        </dependency>  
        <dependency>  
            <groupId>commons-logging</groupId>  
            <artifactId>commons-logging</artifactId>  
            <version>1.1.1</version>  
        </dependency>  
        <dependency>  
            <groupId>net.sf.ezmorph</groupId>  
            <artifactId>ezmorph</artifactId>  
            <version>1.0.6</version>  
        </dependency>  
        <dependency>  
            <groupId>net.sf.json-lib</groupId>  
            <artifactId>json-lib</artifactId>  
            <version>2.2.3</version>  
            <classifier>jdk15</classifier><!-- 指定jdk版本 -->  
        </dependency>  
        <!-- Json依赖架包下载 -->  
View Code
复制代码

 如果需要fastjson的依赖:

    <dependency>  
        <groupId>com.alibaba</groupId>  
        <artifactId>fastjson</artifactId>  
        <version>1.2.28</version>  
    </dependency>  
posted on   小破孩楼主  阅读(3650)  评论(0编辑  收藏  举报
编辑推荐:
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

点击右上角即可分享
微信分享提示