zoukankan      html  css  js  c++  java
  • JSONObject

    1.JSON格式的String 怎么转成 net.sf.json.JSONObject

    1 String jstr="{'json':'jsonvalue','bool':true,'int':1,'double':'20.5'}";
    2 JSONObject json=JSONObject.fromObject(jstr);
    3 boolean bool=json.getBoolean("bool");
    4 int i=json.getInt("int");
    5 double d=json.getDouble("double");
    6 String value=json.getString("json");
    7 System.out.println("bool="+String.valueOf(bool)+"	json="+value+"	int="+i+"	double="+d);

    2.String转为bean

     1 假如你是有一个bean对象
     2 class User{
     3 private String name;
     4 private String psw;
     5 //封装getter/setter省略
     6 }
    String u="{'name':'sail331x','psw':'123456789'}";
    User user=(User)JSONObject.toBean(JSONObject.fromObject(u),User.class);

    3.bean转为JSONString

    1 JSONObject juser=JSONObject.fromObject(user);
    2 String jstr=juser.toString();//这个就变成json字符串了
  • 相关阅读:
    Yum与list结合
    DNS辅助
    DHCP中继
    apache+SSL 搭建https
    vsftpd服务器
    根据Eclipse SVN changelog使用ANT自动打增量包
    SHELL 近期学习
    Tomcat源码学习一
    oracle笔记
    Linux 下安装 SVN服务器
  • 原文地址:https://www.cnblogs.com/juncaoit/p/7831660.html
Copyright © 2011-2022 走看看