Hi,
I'm trying to use a QRegExp as a quick way to find a value in a simple JSON string. Unfortunately I'm not so familiar with regular expressions and the examples I find on the internet don't seem to work with QRegExp.
I have a message like below and I want the 'dev' field :
{"dev":"RSNGSM32", "cmd":"setVoltage", "voltage":7.23}
I tried this :
QRegExp reFindName
( "\"dev\":\"(.+?)\"" );
if( reFindName.indexIn( sMessage ) >= 0 )
{
QString sEqName
= reFindName.
cap(0);
qDebug() << "device name is" << sEqName;
}
QRegExp reFindName( "\"dev\":\"(.+?)\"" );
if( reFindName.indexIn( sMessage ) >= 0 )
{
QString sEqName = reFindName.cap(0);
qDebug() << "device name is" << sEqName;
}
To copy to clipboard, switch view to plain text mode
But it doesn't work. I read the documentation on QRegExp and fooled around with the expression, but got nothing that works.
Any advice would be appreciated.
Best regards,
Marc
Bookmarks