Android java.lang.RuntimeException: illegal property: while getting the string from SOAP Object(KSOAP2)

我的未来我决定 提交于 2019-12-25 03:03:09

问题


I want to get the values from the SOAPObject, as below

   anyType{
        Message=anyType{}; 
        ErrorCode=NoError; 
        ImageStatus=anyType{
            ImageTicket=34320146-2035-461c-abd5-d0cba4ebdd37;   
            CustomerImageId=0584e8b766a4de2177f9ed11d1587f55-1; 
            ProductId=anyType{}; 
            StatusName=New images; 
            StatusId=10; 
            IsPaid=false; 
            ThumbnailImageURL=anyType{}; 
            FinalImagesURL=anyType{
                string=anyType{}; 
              }; 
         }; 
    }; 

And i write the code to get the values

 SoapObject resultBody = (SoapObject) soapEnvelope.bodyIn;

 for (int i = 0; i < resultBody.getPropertyCount(); i++) {

    SoapObject body = (SoapObject) resultBody.getProperty(i);

    customerImageId = body.getProperty("CustomerImageId").toString();// throwing exception
    Constants.StatusId = body.getProperty("StatusId").toString();
    thumbnailImageURL = body.getProperty("ThumbnailImageURL").toString();
    isPaid = body.getProperty("IsPaid").toString();

 }

And its giving me an exception

java.lang.RuntimeException: illegal property: CustomerImageId

can anyone help me?


回答1:


Thanks for your reply @Selvin

My final code is

SoapObject resultBody = (SoapObject) soapEnvelope.bodyIn;

SoapObject body = (SoapObject) resultBody.getProperty(0);

SoapObject statusObject = (SoapObject) body.getProperty("ImageStatus");// added this
customerImageId = body.getProperty("CustomerImageId").toString(); exception
Constants.StatusId = body.getProperty("StatusId").toString();
thumbnailImageURL = body.getProperty("ThumbnailImageURL").toString();
isPaid = body.getProperty("IsPaid").toString();



回答2:


CustomerImageId,StatusId, etc are children of ImageStatus, not direct property of anyType. So access these via object of ImageStatus.



来源:https://stackoverflow.com/questions/33167100/android-java-lang-runtimeexception-illegal-property-while-getting-the-string-f

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!