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 ...
随机推荐
- 详解CorelDRAW中如何合并与拆分对象
合并两个或多个对象可以创建带有共同填充和轮廓属性的单个对象,以便将这些对象转换为单个曲线对象.可以合并的对象包括矩形.椭圆形.多边形.星形.螺纹.图形或文本等,本教程将详解CorelDRAW中关于合并 ...
- python垃圾回收,判断内存占用,手动回收内存,二
以下为例子,判断计算机内存并释放程序内存. # coding=utf8 import time import psutil, gc, commands,os from logger_until imp ...
- pycharm破解补丁的使用
转自 https://www.cnblogs.com/lhuser/p/8040163.html 闲来无事,想学学python的爬虫 http://idea.lanyus.com/ 破解补丁下载 或 ...
- Windows 7 无密码文件共享
Windows7中创建无密码的文件共享的几个步骤: 在“控制面板\所有控制面板项\网络和共享中心\高级共享设置”开启“关闭密码保护共享”和“启用文件和打印机共享”.关闭密码保护共享的操作会启用Gues ...
- 利用广播实现ip拨号——示例
1.创建activity_main.xml <LinearLayout xmlns:android="http://schemas.android.com/apk/res/androi ...
- PostgreSQL存储过程(1)-基于SQL的存储过程
什么是SQL函数? SQL函数包体是一些可执行的SQL语言.同时包含1条以上的查询,但是函数只返回最后一个查询(必须是SELECT)的结果. 除非SQL函数声明为返回void,否则最后一条语句必须是S ...
- 【代码审计】CLTPHP_v5.5.3后台任意文件删除漏洞分析
0x00 环境准备 CLTPHP官网:http://www.cltphp.com 网站源码版本:CLTPHP内容管理系统5.5.3版本 程序源码下载:https://gitee.com/chich ...
- ASP代码审计学习笔记 -4.命令执行漏洞
命令执行漏洞: 保存为cmd.asp,提交链接: http://localhost/cmd.asp?ip=127.0.0.1 即可执行命令 <%ip=request("ip" ...
- Ansible Playbook 使用循环语句
如下,with_items 是循环的对象,with_items 是 python list 数据结构,task 会循环读取 list 里面的值,key 的名称是 item [root@localhos ...
- 系统头文件cmath,cstdlib报错
>C:\Program Files (x86)\Microsoft Visual Studio\\Community\VC\Tools\MSVC\\include\cstdlib(): erro ...