首页 分享 JSON数据解析与存储

JSON数据解析与存储

来源:花匠小妙招 时间:2024-12-19 02:17

data是JSON类型的字符串,形式如:"{unitId:21284,templateId:1,unitType:1,TPdaNodeCheckedLogs:[{checkedTime:'2011-03-29 17:13:02',isChecked:1,latitude:0.0,longitude:0.0,personId:1205,personName:'aa',templateItemId:33},{checkedTime:'2011-03-29 17:29:08',isChecked:1,latitude:0.0,longitude:0.0,personId:1205,personName:'bb',templateItemId:40}]}";

public String saveTemp(String data) {

JSONObject jsonObject = JSONObject.fromObject(data);
    /****对时间做处理******/
//   String[] dateFormats = new String[] {"yyyy-MM-dd HH:mm:ss"};  
   String[] dateFormats = new String[] {"yyyy-MM-dd"};  
       JSONUtils.getMorpherRegistry().registerMorpher(new DateMorpher(dateFormats));

      Map map = new HashMap();
   map.put("TPdaNodeCheckedLogs", TPdaNodeCheckedLog.class);

  TPdaNodeRelateTemplate clientRe = JSONObject
    .toBean(jsonObject,TPdaNodeRelateTemplate.class,map);

      Set clientLog=clientRe.getTPdaNodeCheckedLogs();

   Long unitId=clientRe.getUnitId();
   Long templateId=clientRe.getTemplateId();


   List relate=this.getRelate(unitId,templateId);
   boolean boo=false;
   TPdaNodeRelateTemplate' serverRe = new TPdaNodeRelateTemplate'();
   //如果关联记录存在则更新
   if(relate!=null&&relate.size()>0){
     serverRe = (TPdaNodeRelateTemplate')relate.get(0);
   }
   serverRe.setTemplateId(clientRe.getTemplateId());
   serverRe.setUnitId(clientRe.getUnitId());
   serverRe.setUnitType(clientRe.getUnitType());

   serverRe.setUploadFlag(new Long(1));
   //如果关联记录存在则更新
   if(relate!=null&&relate.size()>0){
    this.update(serverRe);
    message = "0|更新成功!";
    boo=true;
   }
   else{

        this.save(serverRe);
    message = "0|上传成功!";
    boo=true;
   }

}

TPdaNodeRelateTemplate 类

public class TPdaNodeRelateTemplate implements java.io.Serializable {

 private Long id;
 private Long unitId;
 private Long templateId;
 private Long uploadFlag;
 private Long unitType;
 private Set TPdaNodeCheckedLogs = new HashSet(0);

 // Constructors

 /** default constructor */
 public TPdaNodeRelateTemplate() {
 }

 /** full constructor */
 public TPdaNodeRelateTemplate(Long unitId, Long templateId,
   Long uploadFlag, Long unitType, Set TPdaNodeCheckedLogs) {
  this.unitId = unitId;
  this.templateId = templateId;
  this.uploadFlag = uploadFlag;
  this.unitType = unitType;
  this.TPdaNodeCheckedLogs = TPdaNodeCheckedLogs;
 }

 // Property accessors

 public Long getId() {
  return this.id;
 }

 public void setId(Long id) {
  this.id = id;
 }

 public Long getUnitId() {
  return this.unitId;
 }

 public void setUnitId(Long unitId) {
  this.unitId = unitId;
 }

 public Long getTemplateId() {
  return this.templateId;
 }

 public void setTemplateId(Long templateId) {
  this.templateId = templateId;
 }

 public Long getUploadFlag() {
  return this.uploadFlag;
 }

 public void setUploadFlag(Long uploadFlag) {
  this.uploadFlag = uploadFlag;
 }

 public Long getUnitType() {
  return unitType;
 }

 public void setUnitType(Long unitType) {
  this.unitType = unitType;
 }

 public Set getTPdaNodeCheckedLogs() {
  return this.TPdaNodeCheckedLogs;
 }

 public void setTPdaNodeCheckedLogs(Set TPdaNodeCheckedLogs) {
  this.TPdaNodeCheckedLogs = TPdaNodeCheckedLogs;
 }

 }

TPdaNodeCheckedLog类

public class TPdaNodeCheckedLog extends cn.com.sgcc.core.base.BaseBean
  implements java.io.Serializable {

 // Fields

 private Long id;
 private Long relateId;
 private String longitude;
 private String latitude;
 private Long templateItemId;
 private Long isChecked;
 private Long personId;
 private String personName;
 private String checkedTime;
 private Long uploadFlag;

 // Constructors

 /** default constructor */
 public TPdaNodeCheckedLog() {
 }

 /** full constructor */
 public TPdaNodeCheckedLog(Long relateId,String longitude, String latitude, Long templateItemId,
   Long isChecked, Long personId, String personName, String checkedTime,
   Long uploadFlag) {
  this.longitude = longitude;
  this.latitude = latitude;
  this.templateItemId = templateItemId;
  this.isChecked = isChecked;
  this.personId = personId;
  this.personName = personName;
  this.checkedTime = checkedTime;
  this.uploadFlag = uploadFlag;
 }

 // Property accessors

 public Long getId() {
  return this.id;
 }

 public void setId(Long id) {
  this.id = id;
 }

  public Long getRelateId() {
  return relateId;
 }

 public void setRelateId(Long relateId) {
  this.relateId = relateId;
 }

 public String getLongitude() {
  return this.longitude;
 }

 public void setLongitude(String longitude) {
  this.longitude = longitude;
 }

 public String getLatitude() {
  return this.latitude;
 }

 public void setLatitude(String latitude) {
  this.latitude = latitude;
 }

 public Long getTemplateItemId() {
  return this.templateItemId;
 }

 public void setTemplateItemId(Long templateItemId) {
  this.templateItemId = templateItemId;
 }

 public Long getIsChecked() {
  return this.isChecked;
 }

 public void setIsChecked(Long isChecked) {
  this.isChecked = isChecked;
 }

 public Long getPersonId() {
  return this.personId;
 }

 public void setPersonId(Long personId) {
  this.personId = personId;
 }

 public String getPersonName() {
  return this.personName;
 }

 public void setPersonName(String personName) {
  this.personName = personName;
 }

 public String getCheckedTime() {
  return this.checkedTime;
 }

 public void setCheckedTime(String checkedTime) {
  this.checkedTime = checkedTime;
 }

 public Long getUploadFlag() {
  return this.uploadFlag;
 }

 public void setUploadFlag(Long uploadFlag) {
  this.uploadFlag = uploadFlag;
 }

}

http://www.javaeye.com/topic/168818这个帖子很值得一看

相关知识

JSON格式化 json在线解析工具 在线json格式校验
json格式
JSON 语法
前端必备技能:全面解析 Token 在 Web 开发中的应用
Kafka数据安全性、运行原理、存储
内存监控方法、装置、计算机可读存储介质和计算机设备与流程
频率与时间换算器
如何从带回调的通知内的url加载毕加索图像?
共筑数据存储产业,推进数字经济繁荣
3.ElasticSearch分布式数据分析引擎基础概念与使用

网址: JSON数据解析与存储 https://www.huajiangbk.com/newsview1174228.html

所属分类:花卉
上一篇: 已知混凝土的配合比为水泥:砂:石
下一篇: 定额中需乘系数的汇总

推荐分享