01-31-2013 08:14 AM
Hi All,
I am new to BB10 Development.
I have made connection with my server which is sending data in JSON Format. How to parse it. Can anyone help me with this.It will be very helpful for me.
Also how to store the parsed data in database or ArrayList.
Thanks & Regards
Sanjit
01-31-2013 08:39 AM
01-31-2013 08:45 AM
Not sure if you want XML parsing or JSON parsing, since your title is XML and you're talking about JSON. They are different.
You can parse XML this way:
QDomDocument xmlDoc;
QString parseError;
int errorLine = 0;
int errorCol = 0;
xmlDoc.setContent ( response, &parseError, &errorLine, &errorCol);
if (errorLine == 0 && errorCol == 0){
QDomNodeList nodes = xmlDoc.elementsByTagName ( "nodeName" );
if (nodes.length() > 0){
QDomNode node = nodes.item(0);
QDomElement element = node.toElement();
QString stringVal = element.text().trimmed();
}
}
Here are example projects for JSON and XML:
https://github.com/blackberry/Cascades-Samples/tre
https://github.com/blackberry/Cascades-Samples/tre