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.

1
  • 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. Commented Oct 3, 2012 at 3:48

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

2 Comments

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.
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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.