net.sf.JSONObject学习

package com.dean;

public class Address {

    private String road;
    private String street;
    private String province;
    private String no;
    public String getRoad() {
        return road;
    }
    public void setRoad(String road) {
        this.road = road;
    }
    public String getStreet() {
        return street;
    }
    public void setStreet(String street) {
        this.street = street;
    }
    public String getProvince() {
        return province;
    }
    public void setProvince(String province) {
        this.province = province;
    }
    public String getNo() {
        return no;
    }
    public void setNo(String no) {
        this.no = no;
    }
}
package com.dean.test;
import com.dean.Address;

import net.sf.json.JSONObject;

public class Test {

    public static void main(String[] args) {
        String jsonAddrStr = "{\"no\":\"104\",\"province\":\"武汉\",\"road\":\"江夏绿道\",\"street\":\"1号公路林荫大道\"}";
        JSONObject jsonObject =  JSONObject
        .fromObject(jsonAddrStr);
        Address address = (Address)jsonObject.toBean(jsonObject, 
        Address.class);
        System.out.println(address.getNo());
        System.out.println(address.getProvince());
        System.out.println(address.getRoad());
        System.out.println(address.getStreet());

    }

}
阅读更多
文章标签: JSONObject
个人分类: java
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

关闭
关闭
关闭