JSONArray数据转换成java List
原文地址:http://hi.baidu.com/chunying031/item/054f60ab431abcab28ce9de5 packageno.integrasco.ingentia.news.qaedition;
packageno.integrasco.ingentia.news.qaedition; 从页面接收json格式的数据,在java类里面进行解析 StringjsonStr={"name":"zfj","dd":[{"ddr":"1","encrypt":"2","ff":"1","length":"23","ffe":"editStyled","ill":"1","pkor":"2","name":"zfj","isKey":"2","alias":"ffff"}],"addRelations":[{"type":"2","ld":"zfj","ld":"2"}]}; 因为我包中没有fromObject、toList,所以用了下面的方法: importcom.alibaba.fastjson.JSON; . ArrayList<SystemMessageInfo>sysMessageInfoList=JSON.parSEObject(resObj, newTypeReference<ArrayList<SystemMessageInfo>>(){ }); 完整的: 1. importcom.alibaba.fastjson.JSON; publicStringGetMultiLangMessage(Stringkey,StringdefaultString){ try{ if(multiLangMsg.getItemObject()==null){ sysMsgMap=newHashMap<Integer,SystemMessageInfo>(); LinkedHashMap<String,Object>params=newLinkedHashMap<String,Object>(); params.put("clientName",Session.current.getComputerName()); StringresObj=KSOAPServiceUtil.callWCFService( "GetSystemMessageForList",params); Log.e("GetMultiLangMessageresObj",resObj); if(!PosEnvironment.isServiceReturnNull(resObj)){ multiLangMsg.setItemObject("msg"); } if(PosEnvironment.isServiceReturnNull(resObj)){ returndefaultString; else { for(SystemMessageInfosystemMessageInfo:sysMessageInfoList){ sysMsgMap.put(systemMessageInfo.getSysMegNumber(),systemMessageInfo); StringstrValString=""; sysMsgInfo=sysMsgMap.get(Integer.valueOf(key)); if(sysMsgInfo!=null){ strValString=PosEnvironment.getCurrentName(sysMsgInfo.getSysMegName1(),arial; font-size:14px; line-height:21px"> sysMsgInfo.getSysMegName2(),arial; font-size:14px; line-height:21px"> sysMsgInfo.getSysMegName3(),arial; font-size:14px; line-height:21px"> sysMsgInfo.getSysMegName4(),arial; font-size:14px; line-height:21px"> sysMsgInfo.getSysMegName5()); if(PosEnvironment.isNullOrEmpty(strValString)){ strValString=defaultString; returnstrValString; }catch(Exceptione){ if(einstanceofNetworkErrorException){ Session.current.getNavigator().getCurrentScreen().ShowMessageBox( "",e.getMessage(),DialogButtons.OK,newObject[]{POSFEVars.SystemAlertFlag}); else{
2.KSOAPServiceUtil.java //callingforWCFServicebyusingKSoapjar. publicclassKSOAPServiceUtil{ publicstaticStringserviceUrl=""; publicstaticStringnamespace=""; publicstaticStringsoap_action_path=""; /** *theparamsiscallthewebService'sparamsinaccordancewiththeorder *parameter,notnecessarilyinaccordancewiththeparametername. * *@parammethodName *@paramparams *@return */ publicstaticStringcallWCFService(StringmethodName,Object>params){ StringretSoapObj=null; SoapObjectrequest=newSoapObject(namespace,methodName); //Callmethodtosettheparametervalues,thereisnoargumentcan //be //omitted //settheparsmsisjson if(params!=null&¶ms.size()>0){ for(Map.Entry<String,Object>entry:params.entrySet()){ if(((entry.getValue())instanceofInteger) ||(entry.getValue()instanceofBoolean) ||(entry.getValue()instanceofString)){ request.addProperty(entry.getKey().toString(),arial; font-size:14px; line-height:21px"> entry.getValue()); }else{ JSON.toJSONString(entry.getValue(),SerializerFeature.WriteDateUseDateFormat)); //CallingWebservicemethodgeneratesaSOAPrequestmessage //settheWebServiceversion SoapSerializationEnvelopeenvelope=newSoapSerializationEnvelope( SoapEnvelope.VER11); envelope.dotNet=true;//Here,ifsettoTRUE,thentheserverwill //getlessthantheparametervalues //(such //as:thesedataintothedatabaseinit) envelope.bodyOut=request; envelope.encodingStyle="UTF-8"; HttpTransportSEht=newHttpTransportSE(serviceUrl); envelope.setOutputSoapObject(request); ht.call(soap_action_path+methodName,envelope);//usingthecall //methodcall //WebService //method retSoapObj=envelope.getResponse().toString();//WebServicemethod //toobtainthe //returnresults if(retSoapObj.trim().equals("anyType{}")){ retSoapObj="{}"; //calltheWebServicenamespaceandmethod; returnretSoapObj; } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |