前端之家收集整理的这篇文章主要介绍了
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())
-
- }
-
- }