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
Highlighted
Developer
Posts: 164
Registered: ‎07-23-2013
My Device: Blackberry z10
My Carrier: Airtel
Accepted Solution

How to split string in bb-cascades

[ Edited ]
  1. I have a json array data like 

    {"RegistrationResult":"Registered Success:Empid:157:TableName:COMPANY156"}

     

  2. Now how i want split the string and show the list view in qml like the follwing

    Registered Success

    Empid = 157

    TableName = COMPANY156

     

  3. Please tell the concept to split a string and show the result in qml

I can get result for the follwing method: 

 

{"RegistrationResult":["Registered Success","Empid":"157","TableName":"COMPANY156"]}

 

But i dont know how to split the string for first one.. Please help..

___________________________________________________________________________________________

*************Plese *********LIKE**** & ****ACCEPT as Solution*** If you got suggestion for your Query.

@RAJESH SVM ----- Blackberry Mobile App Developer, Blaze, India.
Developer
Posts: 17,019
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: How to split string in bb-cascades

in qml you can use javascript string manipulation like substring.
----------------------------------------------------------
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
Developer
Posts: 1,746
Registered: ‎04-08-2010
My Device: Passport Silver, PRIV
My Carrier: Telekom.de, O2, Vodafone

Re: How to split string in bb-cascades


svmrajesh wrote:
  1. ,......"Registered Success:Empid:157:TableName:COMPANY156"}

     


take a look at QString docu

simply do something like

myString.split(':')

and you get a QStringList and this QStringList is directly mapped to a JavaScript Array in QML

-------------------------------------------------------------------------------
ekke (independent software architect, rosenheim, germany)

BlackBerry Elite Developer
BlackBerry Platinum Enterprise Partner
International Development native Mobile Business Apps
BlackBerry 10 | Qt Mobile (Android, iOS)
Workshops / Trainings / Bootcamps

blog: http://ekkes-corner.org
mobile-development: http://appbus.org Twitter: @ekkescorner
Developer
Posts: 164
Registered: ‎07-23-2013
My Device: Blackberry z10
My Carrier: Airtel

Re: How to split string in bb-cascades

Actually my code is here:

 

void controller::onFinished()
{

	m_succeeded = true;

	m_model->clear();
	QNetworkReply* reply = qobject_cast<QNetworkReply*>(sender());
	ArrayDataModel *model = new ArrayDataModel();

	QString response;
	if (reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt() == 200)
	{
		    JsonDataAccess jda;
	        QVariantMap map = jda.loadFromBuffer(reply->readAll()).toMap();

	        QVariantList addresses = map["RegistrationResult"].toList();
	        qDebug() << "RegistrationResult is " << map["RegistrationResult"].toString();

1. Upto this code is correct and am executed successfully..

2.Now please tell how to get data separately from following concept

JsonDataAccess jda;
	        QVariantMap map = jda.loadFromBuffer(reply->readAll()).toMap();

	        QVariantList addresses = map["RegistrationResult"].toList();
	        qDebug() << "RegistrationResult is " << map["RegistrationResult"].toString();
	        m_temperature = map["RegistrationResult"].toString();

	        QString result;
	        QString empid;
	        QString empid_no;
	        QString companyname;
	        QString::SectionFlag flag = QString::SectionSkipEmpty;

	        empid=addresses.section(':', 1);
	        qDebug() <<"result = "<<addresses.section(':', 1);

 

 

___________________________________________________________________________________________

*************Plese *********LIKE**** & ****ACCEPT as Solution*** If you got suggestion for your Query.

@RAJESH SVM ----- Blackberry Mobile App Developer, Blaze, India.
Developer
Posts: 164
Registered: ‎07-23-2013
My Device: Blackberry z10
My Carrier: Airtel

Re: How to split string in bb-cascades

@Simon:

 

Am tried above code but it doesnt show result.. Please give solution to correct code.

___________________________________________________________________________________________

*************Plese *********LIKE**** & ****ACCEPT as Solution*** If you got suggestion for your Query.

@RAJESH SVM ----- Blackberry Mobile App Developer, Blaze, India.
Developer
Posts: 164
Registered: ‎07-23-2013
My Device: Blackberry z10
My Carrier: Airtel

Re: How to split string in bb-cascades

Thanks to @  Developer

void controller::onFinished()
{

	m_succeeded = true;

	m_model->clear();
	QNetworkReply* reply = qobject_cast<QNetworkReply*>(sender());
	ArrayDataModel *model = new ArrayDataModel();

	QString response;
	if (reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt() == 200)
	{
		    JsonDataAccess jda;
	        QVariantMap map = jda.loadFromBuffer(reply->readAll()).toMap();

	        QVariantList addresses = map["RegistrationResult"].toList();
	        qDebug() << "RegistrationResult is " << map["RegistrationResult"].toString();
	        m_temperature = map["RegistrationResult"].toString();
	        m_temperature=m_temperature.section(':', 0, 0);

	        qDebug() << " New RegistrationResult is " <<m_temperature;
	        qDebug() <<map["RegistrationResult"].toString();


	        emit temperatureChanged();

	        QString result;
	        QString empid;
	        QString empid_no;
	        QString companyname;
	        QString::SectionFlag flag = QString::SectionSkipEmpty;

	       
	        qDebug()<<m_temperature.section(':', 1, 1)<<"  =  "<<m_temperature.section(':', 2, 2); // Shows  result as   Empid = 157

	        m_description=m_temperature.section(':', 4, 4); // retrive result as  COMPANY156
	        emit descriptionChanged();

	        								
	    }
	    else {
	        qDebug() << "Server returned code " << reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
	    }

		emit statusChanged();

	    m_active = false;
	    	emit activeChanged();
	}

 

___________________________________________________________________________________________

*************Plese *********LIKE**** & ****ACCEPT as Solution*** If you got suggestion for your Query.

@RAJESH SVM ----- Blackberry Mobile App Developer, Blaze, India.