Java Json Object Mutual transfer

Source: Internet
Author: User

Official website: http://json-lib.sourceforge.net/

The jar package that needs to be prepared

1. Json-lib-2.4-jdk15.jar Current latest version, http://sourceforge.net/projects/json-lib/files/

2. HttpClient is used to provide efficient, up-to-date, feature-rich client programming toolkits that support the HTTP protocol. http://hc.apache.org/downloads.cgi

3. Commons Lang This set of APIs provides some basic, general-purpose operations and processing, such as the automatic generation of ToString () results. http://commons.apache.org/lang/download_lang.cgi

4. Commons Logging Apache Universal logging Tool http://commons.apache.org/logging/download_logging.cgi

5. Commons Collections provides a fairly good complement to the Java Standard Collections API Http://commons.apache.org/collections/download_ collections.cgi

6. Commons Beanutils uses the reflection mechanism to process the properties of the JavaBean http://commons.apache.org/beanutils/download_beanutils.cgi

7. Ezmorph is a simple Java class library used to convert one object to another object http://sourceforge.net/projects/ezmorph/files/

public class Accesstoken {

Private String Accesstoken;
private int expiresin;

Public String Getaccess_token () {
return this.accesstoken;
}

public void Setaccess_token (String s) {
This.accesstoken = s;
}

public int getexpires_in () {
return this.expiresin;
}

}

Jsonstring= "Object

String jsonstring = "{\" access_token\ ": \" War3a-1vxsrqbrwuhp0d4vbq5s0rtrgrfucxuuwyv7262jq6higpcwsz5ttwmcifjwjllzehlycuz8huo11qqg\ ", \" expires_in\ ": 7200}"
. replace (' "', ' \ ');

Jsonobject JB = jsonobject.fromobject (jsonstring);
Accesstoken AC = (accesstoken) jsonobject.tobean (JB, Accesstoken.class);

Object= "jsonstring

Jsonobject jb1 = Jsonobject.fromobject (AC);
System.out.println (Jb1.tostring ());

Java Json Object Mutual transfer

Related Article

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.