在android studio中获取SOAP对象中的属性childs(Get property childs in SOAP object in android studio)

编程入门 行业动态 更新时间:2024-10-24 22:25:29
在android studio中获取SOAP对象中的属性childs(Get property childs in SOAP object in android studio)

当我尝试从信封中获取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: Codigo

But 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());

更多推荐

本文发布于:2023-07-05 07:03:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1034456.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:象中   属性   SOAP   android   studio

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!