2011-06-27 22 views
7

Estoy usando KSoap2 para llamar a servicios web para mi aplicación de Android. Estoy usando el siguiente código para llamar al servicio web.Android KSoap2: cómo obtener el nombre de propiedad

SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME); 
request.addProperty("PageSize", 20); 
request.addProperty("PageIndex", currentPage); 

SoapSerializationEnvelope soapEnvelope = new SoapSerializationEnvelope(SoapEnvelope.VER11); 
soapEnvelope.dotNet = true; 
soapEnvelope.setOutputSoapObject(request); 
HttpTransportSE aht = new HttpTransportSE(URL); 

try { 
    aht.call(SOAP_ACTION, soapEnvelope); 
    SoapObject result = (SoapObject) soapEnvelope.getResponse(); 

    Log.d("resBundle", String.valueOf(resBundle)); 

    int elementCount = resSoap.getPropertyCount(); 
    for(int i = 0;i<elementCount;i++){ 
    /////////////////////how to get the property name here//////////////// 
    } 

}catch (Exception e) { 
    e.printStackTrace(); 
    return null; 
} 

Recibo la respuesta de los servicios web a la perfección. El String.valueOf de la respuesta es a continuación:

anyType{NewsID=2186; NewsSubject=Lil Wayne Shows Up to Heat Game With Mystery Chick & Drake; NewsDetail=Looks like Weezy found him a main chick! Lil Wayne showed off his mystery girl yet again, this time at the Miami Heat Eastern Conference Finals game. Wanye looked proud to be with his girl while he kept his arm around her for most of the game. Drake was also in attendance with Wanye and it looks like he was having a great time cheering on the Heat as they beat the Bulls in overtime. Chad Ochocinco was also spotted enjoying the game, but Evelyn was no where to be seen. Check out more pics from the Miami game:; NewsArtist=494; ModifiedDate=2011-05-26T12:03:04.567+01:00; CreateDate=26 May, 2011 12:03PM; ImageName=26052011120304.jpg; ImageAlt=anyType{}; ShortNewsDetail=Looks like Weezy found him a main chick! Lil Wayne showed off his mystery girl y; } 

Ahora, puedo conseguir fácilmente el valor de la propiedad con facilidad, pero también quiero conseguir la propiedad de nombre (por ejemplo NewSID, NewsSubject, NewsArtist, ModifiedDate). ¿Cómo obtengo el nombre de la propiedad?

Respuesta

15

Cuando realiza un bucle a través de su respuesta, puede obtener acceso a PropertyInfo desde la propiedad diferente. He utilizado la siguiente configuración para obtener los nombres de los parámetros y los valores que van con ellos:

//Inside your for loop 
PropertyInfo pi = new PropertyInfo(); 
resSoap.getPropertyInfo(i, pi); 
Log.d(TAG, pi.name + " : " + resSoap.getProperty(i).toString()); 

Esto crea un objeto PropertyInfo, añade la información de la propiedad de ese objeto y luego le da acceso a todo esto información. Y luego lo imprime en su LogCat en el formato de "propertyname: propertyvalue"

Cuestiones relacionadas