http后台json解析实例
localhost:8080/hbinterface/orderInterface/sIReverseAccept.do?bizType=4&&bnetAccount=ESBTEST20150522OP&&bnetId=GD101140264&&customerType={accNbr:"13316268440","bnetId":"D101140264","bnetAccount":"ESBTEST20150522OP","contactTelephone":"13316268440","contactPersonName":"13316268440","identitySerialNumber":"13316268440",identityType:1,"nodeId":"100000",
servNbr:"GZ200000008536710189","offeringType":{"offeringSpecId":"GD9900405","servNbr":"GZ200000008536710189","productType":[{"productSpecId":"GD9900404","productAttributeList":[{"attributeId":"1","attributeValue":"1","productSpecId":"GD9900405"},{"attributeId":"1","attributeValue":"1","productSpecId":"GD9900108"}]},{"productSpecId":"GD9900406","productAttributeList":[{"attributeId":"1","attributeValue":"1","productSpecId":"GD9900415"}]}]}}
后台解析:
package com.eshore.ismp.hbinterface.webapi.controller.b; import java.util.ArrayList;
import java.util.List; import javax.servlet.http.HttpServletRequest; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController; import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.eshore.ismp.common.entity.ResultInfo;
import com.eshore.ismp.common.hb.esb.b.CustomerType;
import com.eshore.ismp.common.hb.esb.b.OfferingType;
import com.eshore.ismp.common.hb.esb.b.OnlineAcceptType;
import com.eshore.ismp.common.hb.esb.b.ProductAttributeType;
import com.eshore.ismp.common.hb.esb.b.ProductType;
import com.eshore.ismp.common.util.ConstVal;
import com.eshore.ismp.hbinterface.entity.webapi.ReverseOrderEntity;
import com.eshore.ismp.hbinterface.esb.b.BizAcceptService;
import com.eshore.ismp.hbinterface.respository.webapi.ReverseOrderRepository; /**
* @author mercy
*反向订购接口
*/
@RestController
@RequestMapping("/orderInterface")
public class ReverseAcceptHttpProcess {
private static final Log log = LogFactory.getLog(ReverseAcceptHttpProcess.class);
@Autowired
private BizAcceptService service;
@Autowired
private ReverseOrderRepository dao; /**
* @return
* 集团反向订购
* 只做校验
*/
@RequestMapping("/groupReverseAccept")
public String groupReverseAccept(HttpServletRequest request){
ResultInfo resultInfo = new ResultInfo(ConstVal.RESULT_CODE_SUCCESS, ConstVal.RESULT_DETAIL_SUCCESS, "");
OnlineAcceptType oaType=new OnlineAcceptType();
CustomerType cType=new CustomerType();
OfferingType oType=new OfferingType();
List<ProductType> pTypeList=new ArrayList<ProductType>();
List<ProductAttributeType> lpTypeList=new ArrayList<ProductAttributeType>();
long bizType=Long.parseLong(request.getParameter("bizType"));
String bnetId=request.getParameter("bnetId");
String bnetAccount=request.getParameter("bnetAccount");
log.info("bizType:"+bizType+",bnetId:"+bnetId+",bnetAccount"+bnetAccount+"\n");
oaType.setBizType(bizType);
oaType.setBnetId(bnetId);
//oaType.setBnetAccount(bnetAccount);
String customerType=request.getParameter("customerType");
ReverseOrderEntity entity=new ReverseOrderEntity();
String msg="bizType="+bizType+"&&bnetId="+bnetId+"&&bnetAccount="+bnetAccount+"&&customerType="+customerType;
entity.setMsg(msg);
entity.setType(1);
dao.save(entity);
if(isEmpty(customerType)){
resultInfo.setResult_code(-1);
resultInfo.setResult_detail("参数customerType不能为空");
return JSONObject.toJSONString(resultInfo);
}
JSONObject cuType=(JSONObject) JSONObject.parse(customerType);
String accNbr=cuType.getString("accNbr");
String cbnetId=cuType.getString("bnetId");
String cbnetAccount=cuType.getString("bnetAccount");
String contactTelephone=cuType.getString("contactTelephone");
String contactPersonName=cuType.getString("contactPersonName");
//经办人证件号码
String identitySerialNumber=cuType.getString("identitySerialNumber");
//经办人证件类型
long identityType=cuType.getLongValue("identityType");
String identityAddress=cuType.getString("identityAddress");
String nodeId=cuType.getString("nodeId");
String servNbr=cuType.getString("servNbr");
if(isEmpty(cbnetId)){
resultInfo.setResult_code(-1);
resultInfo.setResult_detail("参数bnetId不能为空");
return JSONObject.toJSONString(resultInfo);
}
if(isEmpty(cbnetAccount)){
resultInfo.setResult_code(-1);
resultInfo.setResult_detail("参数bnetAccount不能为空");
return JSONObject.toJSONString(resultInfo);
}
if(isEmpty(nodeId)){
resultInfo.setResult_code(-1);
resultInfo.setResult_detail("参数nodeId不能为空");
return JSONObject.toJSONString(resultInfo);
}
if(isEmpty(servNbr)){
resultInfo.setResult_code(-1);
resultInfo.setResult_detail("参数servNbr不能为空");
return JSONObject.toJSONString(resultInfo);
}
if(isEmpty(identityType)){
resultInfo.setResult_code(-1);
resultInfo.setResult_detail("参数identityType不能为空");
return JSONObject.toJSONString(resultInfo);
}
if(isEmpty(identitySerialNumber)){
resultInfo.setResult_code(-1);
resultInfo.setResult_detail("参数identitySerialNumber不能为空");
return JSONObject.toJSONString(resultInfo);
}
if(isEmpty(identityAddress)){
resultInfo.setResult_code(-1);
resultInfo.setResult_detail("参数identityAddress不能为空");
return JSONObject.toJSONString(resultInfo);
}
//long state=cuType.getLongValue("state");
log.info("accNbr:"+accNbr+",bnetAccount:"+cbnetAccount+",bnetId"+cbnetId+",contactTelephone:"+contactTelephone
+",contactPersonName:"+contactPersonName+",identitySerialNumber:"+identitySerialNumber+",identityType:"+identityType
+",identityAddress:"+identityAddress+",nodeId:"+nodeId+",servNbr:"+servNbr+"\n");
cType.setAccNbr(accNbr);
//cType.setBnetId(cbnetId);
cType.setBnetAccount(cbnetAccount);
cType.setContactTelephone(contactTelephone);
cType.setCompanyName(contactPersonName);
cType.setIdentitySerialNumber(identitySerialNumber);
cType.setIdentityType(identityType);
cType.setIdentityAddress(identityAddress);
cType.setNodeId(nodeId);
cType.setServNbr(servNbr);
//cType.setState(state);
String offeringType=cuType.getString("offeringType");
log.info("====offeringType:"+offeringType+"\n");
JSONObject ofType=(JSONObject) JSONObject.parse(offeringType);
//String oaccNbr=ofType.getString("accNbr");
//String obnetId=ofType.getString("bnetId");
//String onodeId=ofType.getString("nodeId");
String oofferingSpecId=ofType.getString("offeringSpecId");
String oservNbr=ofType.getString("servNbr");
//oType.setAccNbr(oaccNbr);
//oType.setBnetId(obnetId);
//oType.setNodeId(onodeId);
log.info("offeringSpecId:"+oofferingSpecId+",servNbr:"+oservNbr);
oType.setOfferingSpecId(oofferingSpecId);
oType.setServNbr(oservNbr);
String productTypeList=ofType.getString("productType");
log.info("===productTypeList:"+productTypeList);
List<ProductType> pTypeList1=JSONArray.parseArray(productTypeList,ProductType.class);
for(ProductType pt:pTypeList1){
ProductType pType=new ProductType();
//String pbnetId=pt.getBnetId();
//String pnodeId=pt.getNodeId();
String productSpecId=pt.getProductSpecId();
//pType.setBnetId(pbnetId);
//pType.setNodeId(pnodeId);
pType.setProductSpecId(productSpecId);
log.info("===list productSpecId:"+productSpecId);
List<ProductAttributeType> lpTypeList1=pt.getProductAttributeList();
for(ProductAttributeType ls:lpTypeList1){
ProductAttributeType paType=new ProductAttributeType();
String attributeId=ls.getAttributeId();
String attributeValue=ls.getAttributeValue();
String lproductSpecId=ls.getProductSpecId();
log.info("===AttributeList attributeId:"+attributeId+",attributeValue:"+attributeValue+",productSpecId:"+lproductSpecId);
paType.setAttributeId(attributeId);
paType.setAttributeValue(attributeValue);
paType.setProductSpecId(lproductSpecId);
lpTypeList.add(paType);
}
pType.setProductAttributeList(lpTypeList);
pTypeList.add(pType);
}
oType.setProductList(pTypeList);
oaType.setOfferingType(oType);
oaType.setCustomerType(cType);
log.info("oaTypeToString:"+JSONObject.toJSONString(oaType));
String result=JSONObject.toJSONString(service.newGroupProd(oaType));
return result;
}
/**
* @return
* SI反向订购改号
* 只做校验
*/
@RequestMapping("/sIReverseAccept")
public String sIReverseAccept(HttpServletRequest request){
ResultInfo resultInfo = new ResultInfo(ConstVal.RESULT_CODE_SUCCESS, ConstVal.RESULT_DETAIL_SUCCESS, "");
OnlineAcceptType oaType=new OnlineAcceptType();
CustomerType cType=new CustomerType();
OfferingType oType=new OfferingType();
List<ProductType> pTypeList=new ArrayList<ProductType>();
List<ProductAttributeType> lpTypeList=new ArrayList<ProductAttributeType>();
long bizType=Long.parseLong(request.getParameter("bizType"));
String bnetId=request.getParameter("bnetId");
String bnetAccount=request.getParameter("bnetAccount");
log.info("bizType:"+bizType+",bnetId:"+bnetId+",bnetAccount"+bnetAccount+"\n");
oaType.setBizType(bizType);
oaType.setBnetId(bnetId);
//oaType.setBnetAccount(bnetAccount);
String customerType=request.getParameter("customerType");
ReverseOrderEntity entity=new ReverseOrderEntity();
String msg="bizType="+bizType+"&&bnetId="+bnetId+"&&bnetAccount="+bnetAccount+"&&customerType="+customerType;
entity.setMsg(msg);
entity.setType(2);
dao.save(entity);
if(isEmpty(customerType)){
resultInfo.setResult_code(-1);
resultInfo.setResult_detail("参数customerType不能为空");
return JSONObject.toJSONString(resultInfo);
}
JSONObject cuType=(JSONObject) JSONObject.parse(customerType);
String accNbr=cuType.getString("accNbr");
String cbnetId=cuType.getString("bnetId");
String cbnetAccount=cuType.getString("bnetAccount");
String contactTelephone=cuType.getString("contactTelephone");
String contactPersonName=cuType.getString("contactPersonName");
//经办人证件号码
String identitySerialNumber=cuType.getString("identitySerialNumber");
//经办人证件类型
long identityType=cuType.getLongValue("identityType");
String identityAddress=cuType.getString("identityAddress");
String nodeId=cuType.getString("nodeId");
String servNbr=cuType.getString("servNbr");
if(isEmpty(cbnetId)){
resultInfo.setResult_code(-1);
resultInfo.setResult_detail("参数bnetId不能为空");
return JSONObject.toJSONString(resultInfo);
}
if(isEmpty(cbnetAccount)){
resultInfo.setResult_code(-1);
resultInfo.setResult_detail("参数bnetAccount不能为空");
return JSONObject.toJSONString(resultInfo);
}
if(isEmpty(nodeId)){
resultInfo.setResult_code(-1);
resultInfo.setResult_detail("参数nodeId不能为空");
return JSONObject.toJSONString(resultInfo);
}
if(isEmpty(servNbr)){
resultInfo.setResult_code(-1);
resultInfo.setResult_detail("参数servNbr不能为空");
return JSONObject.toJSONString(resultInfo);
}
if(isEmpty(identityType)){
resultInfo.setResult_code(-1);
resultInfo.setResult_detail("参数identityType不能为空");
return JSONObject.toJSONString(resultInfo);
}
if(isEmpty(identitySerialNumber)){
resultInfo.setResult_code(-1);
resultInfo.setResult_detail("参数identitySerialNumber不能为空");
return JSONObject.toJSONString(resultInfo);
}
if(isEmpty(identityAddress)){
resultInfo.setResult_code(-1);
resultInfo.setResult_detail("参数identityAddress不能为空");
return JSONObject.toJSONString(resultInfo);
}
//long state=cuType.getLongValue("state");
log.info("accNbr:"+accNbr+",bnetAccount:"+cbnetAccount+",bnetId"+cbnetId+",contactTelephone:"+contactTelephone
+",contactPersonName:"+contactPersonName+",identitySerialNumber:"+identitySerialNumber+",identityType:"+identityType
+",identityAddress:"+identityAddress+",nodeId:"+nodeId+",servNbr:"+servNbr+"\n");
cType.setAccNbr(accNbr);
//cType.setBnetId(cbnetId);
cType.setBnetAccount(cbnetAccount);
cType.setContactTelephone(contactTelephone);
cType.setCompanyName(contactPersonName);
cType.setIdentitySerialNumber(identitySerialNumber);
cType.setIdentityType(identityType);
cType.setIdentityAddress(identityAddress);
cType.setNodeId(nodeId);
cType.setServNbr(servNbr);
//cType.setState(state);
String offeringType=cuType.getString("offeringType");
log.info("====offeringType:"+offeringType+"\n");
JSONObject ofType=(JSONObject) JSONObject.parse(offeringType);
//String oaccNbr=ofType.getString("accNbr");
//String obnetId=ofType.getString("bnetId");
//String onodeId=ofType.getString("nodeId");
String oofferingSpecId=ofType.getString("offeringSpecId");
String oservNbr=ofType.getString("servNbr");
//oType.setAccNbr(oaccNbr);
//oType.setBnetId(obnetId);
//oType.setNodeId(onodeId);
log.info("offeringSpecId:"+oofferingSpecId+",servNbr:"+oservNbr);
oType.setOfferingSpecId(oofferingSpecId);
oType.setServNbr(oservNbr);
String productTypeList=ofType.getString("productType");
log.info("===productTypeList:"+productTypeList);
List<ProductType> pTypeList1=JSONArray.parseArray(productTypeList,ProductType.class);
for(ProductType pt:pTypeList1){
ProductType pType=new ProductType();
//String pbnetId=pt.getBnetId();
//String pnodeId=pt.getNodeId();
String productSpecId=pt.getProductSpecId();
//pType.setBnetId(pbnetId);
//pType.setNodeId(pnodeId);
pType.setProductSpecId(productSpecId);
log.info("===list productSpecId:"+productSpecId);
List<ProductAttributeType> lpTypeList1=pt.getProductAttributeList();
for(ProductAttributeType ls:lpTypeList1){
ProductAttributeType paType=new ProductAttributeType();
String attributeId=ls.getAttributeId();
String attributeValue=ls.getAttributeValue();
String lproductSpecId=ls.getProductSpecId();
log.info("===AttributeList attributeId:"+attributeId+",attributeValue:"+attributeValue+",productSpecId:"+lproductSpecId);
paType.setAttributeId(attributeId);
paType.setAttributeValue(attributeValue);
paType.setProductSpecId(lproductSpecId);
lpTypeList.add(paType);
}
pType.setProductAttributeList(lpTypeList);
pTypeList.add(pType);
}
oType.setProductList(pTypeList);
oaType.setOfferingType(oType);
oaType.setCustomerType(cType);
log.info("oaTypeToString:"+JSONObject.toJSONString(oaType));
String result=JSONObject.toJSONString(service.modifyGroupProd(oaType));
return result;
}
public boolean isEmpty(Object obj){
if(null==obj||obj.equals("")){
return true;
}
return false; } }
http后台json解析实例的更多相关文章
- JSON解析实例——使用Json-lib
JSON解析实例——使用Json-lib Json-lib下载及使用 本文介绍用一个类库进行JSON解析. 工具下载地址:http://sourceforge.net/projects/json-li ...
- Json解析实例
using System; using System.Collections.Generic; using System.Runtime.Serialization; using System.Win ...
- Javascript调用C#后台方法及JSon解析
Javascript调用C#后台方法及JSon解析 如何使用Ajax 调用C# 后台方法. 本文目录 如何使用Ajax 调用C# 后台方法. 1.后台(.cs)测试方法 2.前台调用(javasc ...
- Android Json生成及解析实例
JSON的定义: 一种轻量级的数据交换格式,具有良好的可读和便于快速编写的特性.业内主流技术为其提供了完整的解决方案(有点类似于正则表达式 ,获得了当今大部分语言的支持),从而可以在不同平台间进行数据 ...
- Android网络请求框架AsyncHttpClient实例详解(配合JSON解析调用接口)
最近做项目要求使用到网络,想来想去选择了AsyncHttpClient框架开进行APP开发.在这里把我工作期间遇到的问题以及对AsyncHttpClient的使用经验做出相应总结,希望能对您的学习有所 ...
- java后台常用json解析工具问题小结
若排版紊乱可查看我的个人博客原文地址 java后台常用json解析工具问题小结 这里不细究造成这些问题的底层原因,只是单纯的描述我碰到的问题及对应的解决方法 jackson将java对象转json字符 ...
- C# Json.Net解析实例
本文以一个简单的小例子,简述Json.Net的相关知识,仅供学习分享使用,如有不足之处,还请指正. 概述 Json.Net is a Popular high-performance JSON fra ...
- json-lib-2.4-jdk15.jar所需全部JAR包.rar java jsoup解析开彩网api接口json数据实例
json-lib-2.4-jdk15.jar所需全部JAR包.rar java jsoup解析开彩网api接口json数据实例 json-lib-2.4-jdk15.jar所需全部JAR包.rar ...
- android json 解析简单实例
Android JSON解析跟JAVA 的JSON解析原理是一样的. Android自带的JSON方式跟方便,不需要导包啥的.不深究原理了,直接上代码: public class JsonActivi ...
随机推荐
- 1 go 开发环境搭建与简单代码实现
什么是go语言 go是一门并发支持,垃圾回收的编译型 系统编程语言,旨在创造一门具有静态编译语言的高性能和动态语言的高效开发之间拥有一个良好平衡点 的一门编程语言. go有什么优点? 自动垃圾回收机制 ...
- 使用php用IE打开指定网页
$cmd = '"C:\Program Files\Internet Explorer\iexplore.exe" http://www.baidu.com'; exec($cmd ...
- 在Linux上安装SVN服务
1.安装SVNyum install subversion 2.查看版本svnserve --version3.创建目录mkdir -p /web/svndata3.创建repo测试库svnadmin ...
- SpringBoot------8080端口被占用抛出异常
异常信息: The Tomcat connector configured to listen on port failed to start. The port may already be in ...
- SpringMVC由浅入深day01_10@RequestMapping_11controller方法的返回值
10 @RequestMapping 10.1 Url路径映射 @RequestMapping(value="/item")或@RequestMapping("/item ...
- Spring整合quartz2.2.3总结,quartz动态定时任务,Quartz定时任务集群配置
Spring整合quartz2.2.3总结,quartz动态定时任务,Quartz定时任务集群配置 >>>>>>>>>>>>&g ...
- Linux应急响应(三):挖矿病毒
0x00 前言 随着虚拟货币的疯狂炒作,利用挖矿脚本来实现流量变现,使得挖矿病毒成为不法分子利用最为频繁的攻击方式.新的挖矿攻击展现出了类似蠕虫的行为,并结合了高级攻击技术,以增加对目标服务器感染 ...
- RN(八)——react-native-image-viewer & react-native-swiper
以项目(业务GO)为例: react-native-swiper 轮播(用在首页的图集轮播) https://github.com/leecade/react-native-swiper react- ...
- apache下配置php环境
1. apache下载 http://httpd.apache.org/download.cgi 2. php下载 http://windows.php.net/download/ 3. 配置 apa ...
- 项目适配iOS9遇到的一些问题及解决办法(更新两个小问题)
本文转载至 http://www.bubuko.com/infodetail-1110714.html http://www.jianshu.com/p/631bd7f12a38 1.网络请求报错.升 ...