Ultra-simple string handling in JSON format and JSON array format

Source: Internet
Author: User
Tags groovy script

Now there are a lot of tools on the site to deal with JSON format, but I looked for a day, found that most of the need to write the corresponding object class to deal with, more trouble, such as: Gson,json-lib. Gson,json-lib these parameters, such as interfaces, have a fixed number of names and numbers of JSON format that is a lever, not to say. But what I want to do is to deal with the test data file, test data file is the parameter name, the number is not fixed, and I wrote groovy script can only be a file, if use Gosn, and so on, each test file must write an internal class, trouble not to say, reusability is still low.

Finally, it is found that there is a tool class to handle this parameter number or the name is not fixed string super simple, just one method. This is the tool class:Net.sourceforge.plastosome.json.JSON.

The method is json.deserialize (Reader reader).

The subclass of reader is for string type and file, so there is no problem at all. Whether you want to handle [{},{}] or [{}] or [{{}} {{}}] can be resolved successfully. If there is only one JSON in [], then the method return value is a hashmap, and if there is more than one JSON in [], the return value is ArrayList. This is what you can see with the GetClass () method.

Ultra-simple string handling in JSON format and JSON array format

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.