当我尝试从信封中获取Propertys时,我收到此错误:
java.lang.RuntimeException: illegal property: Codigo但我有这个属性,它是正确的,请参阅SoapUI的以下请求:
<CalcPrecoPrazoResponse xmlns="http://tempuri.org/"> <CalcPrecoPrazoResult> <Servicos> <cServico> <Codigo>40010</Codigo> <Valor>17,20</Valor> <PrazoEntrega>1</PrazoEntrega> <ValorMaoPropria>0,00</ValorMaoPropria> <ValorAvisoRecebimento>0,00</ValorAvisoRecebimento> <ValorValorDeclarado>0,00</ValorValorDeclarado> <EntregaDomiciliar>S</EntregaDomiciliar> <EntregaSabado>S</EntregaSabado> <Erro>0</Erro> <MsgErro/> <ValorSemAdicionais>17,20</ValorSemAdicionais> <obsFim/> </cServico> </Servicos> </CalcPrecoPrazoResult> </CalcPrecoPrazoResponse>这是我尝试获取这些值
try { http.call(SOAP_ACTION, envelope); SoapObject resposta = (SoapObject) envelope.getResponse(); frt = new Frete(); frt.setCodigo(Integer.parseInt(resposta.getProperty("Codigo").toString())); frt.setValor(resposta.getProperty("Valor").toString()); frt.setPrazoEntrega(resposta.getProperty("PrazoEntrega").toString()); frt.setValorMaoPropria(resposta.getProperty("ValorMaoPropria").toString()); frt.setValorAvisoRecebimento(resposta.getProperty("ValorAvisoRecebimento").toString()); frt.setEntregaDomiciliar(resposta.getProperty("EntregaDomiciliar").toString()); frt.setEntregaSabado(resposta.getProperty("EntregaSabado").toString()); frt.setErro(resposta.getProperty("Erro").toString()); frt.setMsgErro(resposta.getProperty("MsgErro").toString()); frt.setValorSemAdicionais(resposta.getProperty("ValorSemAdicionais").toString()) frt.setObsFim(resposta.getProperty("ObsFim").toString()); } catch (Exception e){ e.printStackTrace(); return null; }当我用String []返回调用webservice时,这是android studio上的响应
anyType{cServico=anyType{Codigo=40010; Valor=1720; PrazoEntrega=1; ValorMaoPropria=000; ValorAvisoRecebimento=000; ValorValorDeclarado=000; EntregaDomiciliar=S; EntregaSabado=S; Erro=0; MsgErro=anyType{}; ValorSemAdicionais=1720; obsFim=anyType{}; }; }我试过这个解决方案,但这对我不起作用... Android java.lang.RuntimeException:非法属性:从SOAP对象获取字符串(KSOAP2)
PS:我正在使用KSoap2 lib
I was getting this error when i try to get Propertys from an envelope:
java.lang.RuntimeException: illegal property: CodigoBut i have this property and it is correctly, see below request from SoapUI:
<CalcPrecoPrazoResponse xmlns="http://tempuri.org/"> <CalcPrecoPrazoResult> <Servicos> <cServico> <Codigo>40010</Codigo> <Valor>17,20</Valor> <PrazoEntrega>1</PrazoEntrega> <ValorMaoPropria>0,00</ValorMaoPropria> <ValorAvisoRecebimento>0,00</ValorAvisoRecebimento> <ValorValorDeclarado>0,00</ValorValorDeclarado> <EntregaDomiciliar>S</EntregaDomiciliar> <EntregaSabado>S</EntregaSabado> <Erro>0</Erro> <MsgErro/> <ValorSemAdicionais>17,20</ValorSemAdicionais> <obsFim/> </cServico> </Servicos> </CalcPrecoPrazoResult> </CalcPrecoPrazoResponse>This is my try to get these values
try { http.call(SOAP_ACTION, envelope); SoapObject resposta = (SoapObject) envelope.getResponse(); frt = new Frete(); frt.setCodigo(Integer.parseInt(resposta.getProperty("Codigo").toString())); frt.setValor(resposta.getProperty("Valor").toString()); frt.setPrazoEntrega(resposta.getProperty("PrazoEntrega").toString()); frt.setValorMaoPropria(resposta.getProperty("ValorMaoPropria").toString()); frt.setValorAvisoRecebimento(resposta.getProperty("ValorAvisoRecebimento").toString()); frt.setEntregaDomiciliar(resposta.getProperty("EntregaDomiciliar").toString()); frt.setEntregaSabado(resposta.getProperty("EntregaSabado").toString()); frt.setErro(resposta.getProperty("Erro").toString()); frt.setMsgErro(resposta.getProperty("MsgErro").toString()); frt.setValorSemAdicionais(resposta.getProperty("ValorSemAdicionais").toString()) frt.setObsFim(resposta.getProperty("ObsFim").toString()); } catch (Exception e){ e.printStackTrace(); return null; }And this is the response on android studio when i calling the webservice with an String[] return
anyType{cServico=anyType{Codigo=40010; Valor=1720; PrazoEntrega=1; ValorMaoPropria=000; ValorAvisoRecebimento=000; ValorValorDeclarado=000; EntregaDomiciliar=S; EntregaSabado=S; Erro=0; MsgErro=anyType{}; ValorSemAdicionais=1720; obsFim=anyType{}; }; }I have tryed this solution but this not worked for me... Android java.lang.RuntimeException: illegal property: while getting the string from SOAP Object(KSOAP2)
PS:I'm using KSoap2 lib
最满意答案
Codigo , Valor和其他属性是Servicos子项,而不是anyType直接属性。 因此,通过Servicos和cServico的对象链访问这些,如下所示:
SoapObject resposta = (SoapObject) envelope.bodyIn; SoapObject body = (SoapObject) resposta.getProperty(0); SoapObject subResposta = (SoapObject) body.getProperty("Servicos"); SoapObject subRespostaDois = (SoapObject) subResposta.getProperty("cServico");然后才使用subRespostaDois访问soap消息属性:
frt = new Frete(); frt.setCodigo(Integer.parseInt(subRespostaDois.getProperty("Codigo").toString())); frt.setValor(subRespostaDois.getProperty("Valor").toString());Codigo,Valor and other properties are children of Servicos and not direct property of anyType. So access these via chain of objects of Servicos and cServico as follows:
SoapObject resposta = (SoapObject) envelope.bodyIn; SoapObject body = (SoapObject) resposta.getProperty(0); SoapObject subResposta = (SoapObject) body.getProperty("Servicos"); SoapObject subRespostaDois = (SoapObject) subResposta.getProperty("cServico");Only then use subRespostaDois to access soap message properties:
frt = new Frete(); frt.setCodigo(Integer.parseInt(subRespostaDois.getProperty("Codigo").toString())); frt.setValor(subRespostaDois.getProperty("Valor").toString());更多推荐
发布评论