Json-lib-2.4.jar Bug,json when value in string is "[value]" structure, resolves to an array, does not parse into a string

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.