JSON string __JS for parsing interface in Java

Source: Internet
Author: User

1. Interface incoming format

[{"Content": "123", "url": "123"},{"content": "123", "url": "123"}]

2. Code

List<voteoption> parsejsonvote (String options) {
		list<voteoption> List = new Arraylist<voteoption > ();
		Jsonarray Arry = jsonarray.fromobject (options);
		for (int i = 0; i < arry.size (); i++) {
			Jsonobject obj = Arry.getjsonobject (i);
			voteoption JB = (voteoption) jsonobject.tobean (obj, voteoption.class);
			List.add (JB);
		}
		return list;
	}
Where Voteoption is the custom entity class

3. Another mode of conversion

Jsonarray Userarray = new Jsonparser (). Parse (JSON string with array). Getasjsonobject (). Get ("array name"). Getasjsonarray ();

Jsonobject obj = new Jsonparser (). Parse (JSON string). Getasjsonobject ();
The two import jar packages are different, 2 jsonarray and so on the package is Com.google.gson, and 3 jsonarray, such as the package is Net.sf.json.


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.