Today I want to convert a string type to a JSON array format, but always report java.lang.noclassdeffounderror errors, and finally I solve the problem, the following steps to solve
First, the introduction of the package
It is not enough to introduce a json-lib jar package for the program to be introduced, and the following additional packages must be introduced
1, Commons-beanutils.jar
2, Commons-collections-3.2.jar
3, Commons-lang-2.5.jar
4, Commons-logging-1.1.1.jar
5, Ezmorph-1.0.4.jar
6, Json-lib-2.4-jdk15.jar
The introduction of these packages to ensure the normal operation of abbreviated code
Ii. specific applications (use of Jsonarray)
Package zyj.com;
Import java.util.List;
Import Net.sf.json.JSONArray;
public class Jsontest {public
static void Main (string[] args) {
Jsonarray jsonobject = Jsonarray.fromobject ("[{] Name ': ' Huangbiao ', ' age ': 15},{' name ': ' Liumei ', ' Age ':}] ';
List<studentpo> student=jsonobject.tolist (jsonobject,studentpo.class);
for (Studentpo studentpo:student) {
System.out.println (studentpo.getname () + ";" +studentpo.getage ());}}
Results:
Huangbiao;15
liumei;14
Iii. the difference between Jsonarray and Jsonobject
Jsonobject is an object that is wrapped up in {};
Jsonarray is an array of [] wrapped;