net.sf.JSONObject学习

前端之家收集整理的这篇文章主要介绍了net.sf.JSONObject学习前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
  1. package com.dean;
  2.  
  3. public class Address {
  4.  
  5. private String road;
  6. private String street;
  7. private String province;
  8. private String no;
  9. public String getRoad() {
  10. return road;
  11. }
  12. public void setRoad(String road) {
  13. this.road = road;
  14. }
  15. public String getStreet() {
  16. return street;
  17. }
  18. public void setStreet(String street) {
  19. this.street = street;
  20. }
  21. public String getProvince() {
  22. return province;
  23. }
  24. public void setProvince(String province) {
  25. this.province = province;
  26. }
  27. public String getNo() {
  28. return no;
  29. }
  30. public void setNo(String no) {
  31. this.no = no;
  32. }
  33. }
  1. package com.dean.test;
  2. import com.dean.Address;
  3.  
  4. import net.sf.json.JSONObject;
  5.  
  6. public class Test {
  7.  
  8. public static void main(String[] args) {
  9. String jsonAddrStr = "{\"no\":\"104\",\"province\":\"武汉\",\"road\":\"江夏绿道\",\"street\":\"1号公路林荫大道\"}";
  10. JSONObject jsonObject = JSONObject
  11. .fromObject(jsonAddrStr);
  12. Address address = (Address)jsonObject.toBean(jsonObject,Address.class);
  13. System.out.println(address.getNo());
  14. System.out.println(address.getProvince());
  15. System.out.println(address.getRoad());
  16. System.out.println(address.getStreet());
  17.  
  18. }
  19.  
  20. }

猜你在找的Json相关文章