67,516
社区成员
发帖
与我相关
我的任务
分享
public String createJson(){
try{
JSONObject jsonObject=new JSONObject();
jsonObject.put("id","1");
jsonObject.put("name","李磊");
jsonObject.put("age",30);
return jsonObject.toString();
}catch(Exception e){
e.printStackTrace();
}
return "";
}
public String createJson(){
JSONObject jsonObject=null;
try{
jsonObject=new JSONObject();
jsonObject.put("id","1");
jsonObject.put("name","李磊");
jsonObject.put("age",30);
}catch(Exception e){
e.printStackTrace();
}
return null!=jsonObject?jsonObject.toString():"";
}
也可以这么写,估计好理解点