A bug was found when the JSON string was converted to an object using Json-lib.jar 2.4. Paste the test code:
<dependency> <groupId>net.sf.json-lib</groupId> <artifactid>json-lib</ artifactid> <version>2.4</version> <classifier>jdk15</classifier> </ dependency> <dependency> <groupId>com.alibaba</groupId> <artifactId> fastjson</artifactid> <version>1.2.12</version> </dependency>
Public classTest { Public Static voidMain (string[] args) {String json= "{' user ': [{' Name ': ' Zs ', ' score ': ' [0-100] '}," + "{' name ': ' Zs ', ' score ': ' [0-100] '}]}"; Test_json_lib (JSON); Test_fastjson (JSON); } Public Static voidTest_json_lib (String json) {net.sf.json.JSONObject obj=Net.sf.json.JSONObject.fromObject (JSON); System.out.println ("json-lib=====" +obj.tostring ()); } Public Static voidTest_fastjson (String json) {com.alibaba.fastjson.JSONObject obj=Com.alibaba.fastjson.JSONObject.parseObject (JSON); System.out.println ("fastjson=====" +obj); }}
Output Result:
json-lib====={"User": [{"Name": "Zs", "Score": ["0-100"]},{"name": "Zs", "Score":["0-100"]}]} Fastjson====={"user": [{"Name": "Zs", "Score": "[0-100]"},{"name": "Zs", "Score":"[0-100]"}]}
I tested the use of Json-lib and Ali Fastjson, the result is as follows: Found json-lib the value of score as an array (originally a string "[0-100]"), Fastjson conversion Normal.
Json-lib-2.4.jar Bug,json when value in string is "[value]" structure, resolves to an array, does not parse into a string