Java-JSONArray jsonArray = JSONArray.fromObject()使用
背景:获取结果为["1","2","3"]的类型为object,想要获取里边的数据值,只能转换为JSONArray,下边记录一下我转换的过程!
1.添加依赖的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> <!-- 这里注意jdk版本 --> <dependency> <groupId>net.sf.json-lib</groupId> <artifactId>json-lib</artifactId> <version>2.2.3</version> <classifier>jdk15</classifier> </dependency>
2.类引用
import net.sf.json.JSONArray; JSONArray jsonArray = JSONArray.fromObject(object);