Today, when writing Javaweb project, we need to transmit JSON format data to the foreground, and use a series of packages such as Json-lib-2.4-jdk15.jar, however, the following conditions appear:
Citybean is a javabean, we see that the console only prints out the contents of the list, and the following two are not able to print, this shows that the program executes to JSON.Array.fromObject () when the termination, and the console did not report any errors, and no exception thrown, Particularly strange.
The following is a package for JSON import:
First of all, the number of packages is correct, and all I downloaded from the official website, are the latest version, so at first I did not focus on the jar package.
Later saw on the Internet that the list of JavaBean contains other entity attributes, printed out is a memory value, in the process of converting the JSON exception, the entity attributes converted to a string to repopulate, so I rewrite the ToString () method in Citybean:
Unfortunately Jsonarray.fromobject () still does not execute ...
Later wrote a test with JUnit debugging a bit, finally reported abnormal
I can't find the class under Lang???? I have imported the Lang package clearly.
It is said that Tomcat is looking for the jar in its own Lib directory, and if the jar package is not stored in the Tomcat Lib directory, it will not be found. But I still reported the same mistake after I put it in.
Finally, I finally found that I import is Commons-lang3-3.7.jar, and the program needs is Commons-lang jar package, later went to the official website to see the previous version, sure enough 2.x packet Lang behind not immediately followed by the number, the same commons-collections4-4.2.jar should also be replaced by The previous version.
Demo by:
Normal execution of the program:
Jsonarray.fromobject does not perform and does not answer the problem