今天下午在Maven项目中使用JSON的时候遇到了很多问题,
比如输出对象时输出的是地址:
getBooksById>>{indi.marcus.demo.model.Book@28b0599}
通过JSONObject.fromObject(book)转成JSON字符串如下:
getBookById>>{“author”:“罗贯中”,“name”:“三国演义”,“id”:1}
以下是使用JSON需要进入的6个依赖包
<!-- 添加JSON依赖-->
<dependency>
<groupId>net.sf.json-lib</groupId>
<artifactId>json-lib</artifactId>
<version>2.4</version>
<!-- 必须添加JDK版本号-->
<classifier>jdk15</classifier>
</dependency>
<dependency>
<groupId>commons-beanutils</groupId>
<artifactId>commons-beanutils</artifactId>
<version>1.9.2</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.5</version>
</dependency>
<dependency>
<groupId>net.sf.ezmorph</groupId>
<artifactId>ezmorph</artifactId>
<version>1.0.3</version>
</dependency>
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
<version>1.2</version>
</dependency>