json 解析

*List<OrderRecord>   orderRecordList   =   orderRecordDAO.findByProductInstanceId(productInstanceId);
     if(orderRecordList != null && orderRecordList.size() > 0 ){
//      for(OrderRecord o : orderRecordList){
        OrderRecordDTO oDto = new OrderRecordDTO();
        BeanUtility.copyProperties(oDto, orderRecordList.get(0));
        Integer bizType =  oDto.getBusinessType().getValue();
       if("1".equals(bizType) || bizType ==1){
        String jsonStr = oDto.getExtInfo();
        if(jsonStr != null){
         JSONObject jsonObj = null;
      try {
       jsonObj = new JSONObject(jsonStr);
       String domain = jsonObj.getString("bindDomain");
       oDto.setBindDomain(domain);
      } catch (JSONException e) {
       // TODO Auto-generated catch block
       e.printStackTrace();
      }
        }
       }
       return oDto;
      }
         return null;*/
//     ZmailProductInstanceAttr zmailProInstArr = zmailProInstAttrDAO.findByProductInstId(productInstanceId);
//     if(zmailProInstArr !=null){
//       OrderRecordDTO oDto = new OrderRecordDTO();
//       oDto.setBindDomain(zmailProInstArr.getBindDomain());
//       return oDto;

 

 

 

 

 

 

json  --import org.json.JSONArray;-- 注意格式是式{changeRecord:[{productInstanceId:001,changeRecordTypeInt:300,custId:ce,productIdInt:001,extMsg:{domian:300.cn}},{...}]}

《《《《《《------------------------------------------------------------------------------
public class BusinessUpdateAction extends BaseAction{
 private static final long serialVersionUID = 1L;
 //信息格式{changeRecord:[{productInstanceId:001,changeRecordTypeInt:300,custId:ce,productIdInt:001,extMsg:{domian:300.cn}},{...}]}
 String jsonStr;
 //返回信息
 String message;
  @Resource
  ChangeRecordBiz changeRecordBiz;
 //定购记录id
  String orderId;
 public String getOrderId() {
  return orderId;
 }
 public void setOrderId(String orderId) {
  this.orderId = orderId;
 }
 @Action(value = "businessUpdate",
   results = { @Result(type = "json", name = "businessUpdate", params = { "root", "message" }) })
 @Transactional(propagation = Propagation.REQUIRED, readOnly = false)
 public String businessUpdate(){
  try{
   if(jsonStr!=null)
   {
    JSONObject jsonObject = JSONObject.fromObject(jsonStr);
    JSONArray array=jsonObject.getJSONArray("changeRecord");
    for(int i=0;i<array.size();i++)
    {
     JSONObject obj=array.getJSONObject(i);
     System.out.println(obj.get("productInstanceId").toString());
     System.out.println(obj.get("extMsg").toString());
     //ChangeRecordDTO changeRecord
     ChangeRecordDTO dto=(ChangeRecordDTO)obj.toBean(obj, ChangeRecordDTO.class);
     dto.setExtMsg(obj.getString("extMsg"));
     changeRecordBiz.createChangeRecord(dto, this.getLoginUser());
    }
   }
   this.setMessage("1");
  }catch(Exception e){
   e.printStackTrace();
   System.out.println(e.getMessage());
   this.setMessage(e.getMessage());
  }
  
  //orderBiz.saveOrder(orderDTO);
  //this.getRequest().setAttribute("orderId", "2321321312321");
  //orderId="2321321312321";
  this.setOrderId(orderId);
  return "businessUpdate";
 }
 public String getJsonStr() {
  return jsonStr;
 }
 public void setJsonStr(String jsonStr) {
  this.jsonStr = jsonStr;
 }
 public String getMessage() {
  return message;
 }
 public void setMessage(String message) {
  this.message = message;
 }
 
 public static void main(String...strings)
 {
  JSONObject jsonObject = JSONObject.fromObject("{changeRecord:[{productInstanceId:001,changeRecordTypeInt:300," +
    "custId:'ce',productIdInt:001,extMsg:{domian:'300.cn'}}]}");
  JSONArray array=jsonObject.getJSONArray("changeRecord");
  for(int i=0;i<array.size();i++)
  {
   JSONObject obj=array.getJSONObject(i);
   System.out.println(obj.get("productInstanceId").toString());
   System.out.println(obj.get("extMsg"));
   JSONObject jsonObject2 = JSONObject.fromObject(obj.get("extMsg"));
   System.out.println(jsonObject2.get("domian"));
   //ChangeRecordDTO changeRecord
   ChangeRecordDTO dto=(ChangeRecordDTO)obj.toBean(obj, ChangeRecordDTO.class);
   dto.setExtMsg(obj.getString("extMsg"));
   
   //changeRecordBiz.createChangeRecord(dto, this.getLoginUser());
  }
 }
}

json  --import org.json.JSONArray;-- 注意格式是[{"key","value"}]

《《《《《《------------------------------------------------------------------------------

private static List<ZmailAlias> getAlias(String s,String icp) {
  if (StringUtility.isNotBlank(s)) {
   JSONArray json;
   try {
    json = new JSONArray(s);
    List<ZmailAlias> a = new ArrayList<ZmailAlias>();
    for(int i=0 ;i<json.length();i++){
     ZmailAlias bie = new ZmailAlias();
     bie.setAlias(json.getJSONObject(i).getString("alias"));
     if(StringUtility.isNotBlank(icp)){
      bie.setIcp(icp);
     }
     bie.setRemark(json.getJSONObject(i).getString("remark"));
     a.add(bie);
    }
    return a;
   } catch (Exception e) {
    throw new BizLogicException("zmail别名解析失败!");
   }
   
  }
  return null;
 }

 

 

 

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值