Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Native Development

Reply
Developer
Posts: 16,992
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany
Accepted Solution

Work with arrays on a webservice response

I am using QtSoap to receive a reply from a webservice, it mainly consists of three big arrays full of items.

I am a bit lost how to handle the responses, especially the arrays.

 

Don't hesitate to improve any part of my code, as a java developer i am collecting code pieces from all parts of the web and try to get them running together Smiley Happy 

 

What i have managed so far is to iterate over the response and "find" the relevant arrays.

But how do i convert the item to an array? My feeble attempts so far did no succeed. 

 

const QtSoapMessage& resp = m_soap.getResponse();
QtSoapStruct &m = (QtSoapStruct &) resp.method();
for (QtSoapStructIterator it(m); it.current(); ++it) {
	QtSoapType *item = it.data();
	if (QString::compare("Attributes", item->name().name()) == 0) {
			qDebug() << "Attributes found";
	} else if (QString::compare("Box", item->name().name()) == 0) {
			qDebug() << "Box found";
	} else if (QString::compare("Tabs", item->name().name()) == 0) {
			qDebug() << "Tabs found";
	} else if (QString::compare("Version", item->name().name()) == 0) {
			qDebug() << "Version: "+item->value().toString();
	}
}

 

 

----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Retired
Posts: 32
Registered: ‎05-09-2012
My Device: BB10
My Carrier: None

Re: Work with arrays on a webservice response

Haven't tried it myself but I believe you can cast your QtSoapType items to QtSoapArray if they are of that type.

QtSoapType *item = it.data();

 

if (item != NULL && item->type() == QtSoapType::Array)

{

    QtSoapArray* array = (QtSoapArray*)item;

    // now work with array

}

Let me know if it works.
Retired
Posts: 32
Registered: ‎05-09-2012
My Device: BB10
My Carrier: None

Re: Work with arrays on a webservice response

Hi Simon,

Have you been able to try this yet?

Thanks!
Daniel
Developer
Posts: 16,992
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: Work with arrays on a webservice response

Hi Daniel, thanks for your reply. It seems that tge QtSoapType is quite flexible and you can cast it to whatever you like.

QtSoapStruct allows to access items by name, while QtSoapArray allows iterating them.

 

My code looks like this now: 

 

QtSoapStruct &soapStruct = (QtSoapStruct &) resp.method();
QtSoapArray &attributes = (QtSoapArray &) soapStruct["Attributes"];

 I will add the null and type check, did not know how to do that so far Smiley Happy

 

----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Highlighted
Retired
Posts: 32
Registered: ‎05-09-2012
My Device: BB10
My Carrier: None

Re: Work with arrays on a webservice response

So does that fully answer your question?  If so, can you mark a post as a solution.  If not, how can we help?

 

Thanks!

Daniel