1

I am reading a JSON file using Qfile. Storing it in to a Qstring object. While passing the QString object to Parser::parse(), it is showing the compilation error as The function parse() only accepts QIODevice* or const QByteArray& as first argument.

The exact error message is:

no matching function for call to QJson::Parser::(QString,bool*)

candidates are Qvariant QJson::Parser::parse(QIODevice*,bool*)

note QVariant Qjson::Parser::parse(const QByteArray&,bool*)

I tried to cast QString to QIODevice and QByteArray, but all in vain.

pb2q
  • 58,613
  • 19
  • 146
  • 147
  • Are you sure that is the _exact_ error message? The first line "no matching function for call to QJson::Parser::(QString,bool*)" looks wrong, surely that should be `QJson::Parser::parse`? Also, for help with compilation errors, please show the code as well as the errors. – rohanpm Oct 03 '12 at 03:48

1 Answers1

1

Use QString::toUtf8(), which converts a QString to a QByteArray

Chris
  • 17,119
  • 5
  • 57
  • 60
  • `QString::toAscii()` is only correct if he knows that the data will only contain ASCII characters. It will destroy non-ASCII data (e.g. Chinese, Japanese, Korean characters). JSON usually uses UTF8 encoding, so `QString::toUtf8()` is most likely the right answer here. – rohanpm Oct 03 '12 at 03:51
  • after every thing also i m unable to run a web service and parse the json. pliz provide me a sample code to run webservice and read the json and parse it. Actually this is my 1st app in Qt. – user1715145 Oct 06 '12 at 11:28