[Qt-interest] Problem with RegExp extraction value from Json kind of response
Christopher Probst
cprobst at ics.com
Thu Mar 25 11:25:04 CET 2010
Hello Meir
Using the regexp tester provided by Qt in
$QTDIR/examples/tools/regexp
the following works for me:
#include <QDebug>
#include <QRegExp>
int main(int argc, char *argv[])
{
QString http_response = "{\"key\":\"a99fdd865c2-10000\",\"oid\":
1000055,\"expires\":0000,\"secret\":\"509c03edfdc7\",\"sign\":
\"f0dd9e5226d0e77\"}";
QRegExp rx("\"key\":\"(.*)\",");
rx.setMinimal(true);
int yy = rx.indexIn(http_response);
qDebug() << yy;
qDebug() << rx.cap(0);
qDebug() << rx.cap(1);
}
gives me
1
""key":"a99fdd865c2-10000","
"a99fdd865c2-10000"
For more details see:
http://doc.trolltech.com/4.6/tools-regexp.html
Thanks,
Christo
On 25 Mar 2010, at 07:32, Meir Yanovich wrote:
> Hello all
> im trying to extract value by key from http Json kind of struct by
> using simple RegExp
> here is my code i like to extract the key value from the string:
>
> QString http_response = "{\"key\":\"a99fdd865c2-10000\",\"oid\":
> 1000055,\"expires\":0000,\"secret\":\"509c03edfdc7\",\"sign\":
> \"f0dd9e5226d0e77\"}";
> // or even if i use QRegExp::escape on the string it dosn't work
> QRegExp rx("\"key\"\:(.*?)\",");
> int yy = rx.indexIn(http_response);
> QString cap = rx.cap(1);
>
> but i cant capture the string and the yy variable always gives me -1
> i tested this regexp in this regexp tester : http://gskinner.com/RegExr/
> and its working fine
> what im doing wrong here ?
>
> _______________________________________________
> Qt-interest mailing list
> Qt-interest at trolltech.com
> http://lists.trolltech.com/mailman/listinfo/qt-interest
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20100325/4daaed58/attachment.html
More information about the Qt-interest-old
mailing list