import com.google.gson.JsonObject
import org.json.JSONObject
- 方法
public void sendEmailUseXUrl( EmailXSendParams emailXSendParams){
JSONObject jsonObject=new JSONObject();
jsonObject.put("appid","");
jsonObject.put("name",emailXSendParams.getAppId());
System.out.println(jsonObject.toString());
JsonObject jsonObject1=new JsonObject();
jsonObject1.addProperty("appId","");
jsonObject1.addProperty("name",emailXSendParams.getAppId());
System.out.println(jsonObject1.toString());
}
public void sendEmailUseXUrl() {
EmailXSendParams emailXSendParams=new EmailXSendParams();
emailService.sendEmailUseXUrl(emailXSendParams);
}
{"appid":""}
{"appId":"","name":null}
- 观察:当对象中的参数为null时,gson会正常生成Json格式,而json会将其忽略
- 结论:因势利导,善用之!
网友评论