QT5.7 - 为什么我使用 QString 得到格式错误的 json 值,但使用 std::string 却完美无缺?

QT5.7 - Why i get a malformed json value with QString but perfect with std::string?

我尝试在 Rails 上从 Ruby 中的 api 获得 json 响应。

当我直接用 curlpostman 调用这个 url 时,我得到了一个完美的 json响应。

当我将我的程序与 QT5.7 windows 一起用于 32 位程序的静态编译时,只有使用 std::string 我才能得到完美的响应.

但是,如果我使用 QDebug 打印 QString(),我会得到这个格式错误且奇怪的结果:

"{\"success\":true,\"files\":[\"C:/Perl/lib/pods/perlcn.pod\",\"C:/Perl/lib/pods/perldata.pod\",\"C:/Perl/lib/pods/perldebguts.pod\",\"C:/Perl/lib/pods/perldelta.pod\",\"C:/Perl/lib/pods/perldiag.pod\",\"C:/Perl/lib/pods/perldoc.pod\",\"C:/Perl/lib/pods/perldos.pod\",\"C:/Perl/lib/pods/perldsc.pod\",\"C:/Perl/lib/pods/perldtrace.pod\",\"C:/Perl/lib/pods/perlebcdic.pod\",\"C:/Perl/lib/pods/perlembed.pod\",\"C:/Perl/lib/pods/perlexperiment.pod\",\"C:/Perl/lib/pods/perlfaq.pod\",\"C:/Perl/lib/pods/perlfaq1.pod\",\"C:/Perl/lib/pods/perlfaq2.pod\",\"C:/Perl/lib/pods/perlfaq3.pod\",\"C:/Perl/lib/pods/perlfaq4.pod\",\"C:/Perl/lib/pods/perlfaq5.pod\",\"C:/Perl/lib/pods/perlfaq6.pod\",\"C:/Perl/lib/pods/perlfaq7.pod\",\"C:/Perl/lib/pods/perlfaq8.pod\",\"C:/Perl/lib/pods/perlfaq9.pod\",\"C:/Perl/lib/pods/perlfilter.pod\",\"C:/Perl/lib/pods/perlfork.pod\",\"C:/Perl/lib/pods/perlform.pod\",\"C:/Perl/lib/pods/perlfreebsd.pod\",\"C:/Perl/lib/pods/perlfunc.pod\",\"C:/Perl/lib/pods/perlgit.pod\",\"C:/Perl/lib/pods/perlglossaîv

所以,如果我打印 std::string,我有一个完美的 json,正是我想要的:

{"success":true,"files":["C:/Perl/lib/pods/perlcn.pod","C:/Perl/lib/pods/perldata.pod","C:/Perl/lib/pods/perldebguts.pod","C:/Perl/lib/pods/perldelta.pod","C:/Perl/lib/pods/perldiag.pod","C:/Perl/lib/pods/perldoc.pod","C:/Perl/lib/pods/perldos.pod","C:/Perl/lib/pods/perldsc.pod","C:/Perl/lib/pods/perldtrace.pod","C:/Perl/lib/pods/perlebcdic.pod","C:/Perl/lib/pods/perlembed.pod","C:/Perl/lib/pods/perlexperiment.pod","C:/Perl/lib/pods/perlfaq.pod","C:/Perl/lib/pods/perlfaq1.pod","C:/Perl/lib/pods/perlfaq2.pod","C:/Perl/lib/pods/perlfaq3.pod","C:/Perl/lib/pods/perlfaq4.pod","C:/Perl/lib/pods/perlfaq5.pod","C:/Perl/lib/pods/perlfaq6.pod","C:/Perl/lib/pods/perlfaq7.pod","C:/Perl/lib/pods/perlfaq8.pod","C:/Perl/lib/pods/perlfaq9.pod","C:/Perl/lib/pods/perlfilter.pod","C:/Perl/lib/pods/perlfork.pod","C:/Perl/lib/pods/perlform.pod","C:/Perl/lib/pods/perlfreebsd.pod","C:/Perl/lib/pods/perlfunc.pod","C:/Perl/lib/pods/perlgit.pod","C:/Perl/lib/pods/perlglossary.pod","C:/Perl/lib/pods/perlgpl.pod","C:/Perl/lib/pods/perlguts.pod","C:/Perl/lib/pods/perlhack.pod","C:/Perl/lib/pods/perlhacktips.pod","C:/Perl/lib/pods/perlhacktut.pod","C:/Perl/lib/pods/perlhaiku.pod","C:/Perl/lib/pods/perlhist.pod","C:/Perl/lib/pods/perlhpux.pod","C:/Perl/lib/pods/perlhurd.pod","C:/Perl/lib/pods/perlintern.pod","C:/Perl/lib/pods/perlinterp.pod","C:/Perl/lib/pods/perlintro.pod","C:/Perl/lib/pods/perliol.pod","C:/Perl/lib/pods/perlipc.pod","C:/Perl/lib/pods/perlirix.pod","C:/Perl/lib/pods/perljp.pod","C:/Perl/lib/pods/perlko.pod","C:/Perl/lib/pods/perllexwarn.pod","C:/Perl/lib/pods/perllinux.pod","C:/Perl/lib/pods/perllocale.pod","C:/Perl/lib/pods/perllol.pod","C:/Perl/lib/pods/perlmacos.pod","C:/Perl/lib/pods/perlmacosx.pod","C:/Perl/lib/pods/perlmod.pod","C:/Perl/lib/pods/perlmodinstall.pod","C:/Perl/lib/pods/perlmodlib.pod","C:/Perl/lib/pods/perlmodstyle.pod","C:/Perl/lib/pods/perlmroapi.pod","C:/Perl/lib/pods/perlnetware.pod","C:/Perl/lib/pods/perlnewmod.pod","C:/Perl/lib/pods/perlnumber.pod","C:/Perl/lib/pods/perlobj.pod","C:/Perl/lib/pods/perlootut.pod","C:/Perl/lib/pods/perlop.pod","C:/Perl/lib/pods/perlopenbsd.pod","C:/Perl/lib/pods/perlopentut.pod","C:/Perl/lib/pods/perlos2.pod","C:/Perl/lib/pods/perlos390.pod","C:/Perl/lib/pods/perlos400.pod","C:/Perl/lib/pods/perlpacktut.pod","C:/Perl/lib/pods/perlperf.pod","C:/Perl/lib/pods/perlplan9.pod","C:/Perl/lib/pods/perlpod.pod","C:/Perl/lib/pods/perlpodspec.pod","C:/Perl/lib/pods/perlpodstyle.pod","C:/Perl/lib/pods/perlpolicy.pod","C:/Perl/lib/pods/perlport.pod","C:/Perl/lib/pods/perlpragma.pod","C:/Perl/lib/pods/perlqnx.pod","C:/Perl/lib/pods/perlre.pod","C:/Perl/lib/pods/perlreapi.pod","C:/Perl/lib/pods/perlrebackslash.pod","C:/Perl/lib/pods/perlrecharclass.pod","C:/Perl/lib/pods/perlref.pod","C:/Perl/lib/pods/perlreftut.pod","C:/Perl/lib/pods/perlreguts.pod","C:/Perl/lib/pods/perlrepository.pod","C:/Perl/lib/pods/perlrequick.pod","C:/Perl/lib/pods/perlreref.pod","C:/Perl/lib/pods/perlretut.pod","C:/Perl/lib/pods/perlriscos.pod","C:/Perl/lib/pods/perlrun.pod","C:/Perl/lib/pods/perlsec.pod","C:/Perl/lib/pods/perlsolaris.pod","C:/Perl/lib/pods/perlsource.pod","C:/Perl/lib/pods/perlstyle.pod","C:/Perl/lib/pods/perlsub.pod","C:/Perl/lib/pods/perlsymbian.pod","C:/Perl/lib/pods/perlsyn.pod","C:/Perl/lib/pods/perlsynology.pod","C:/Perl/lib/pods/perlthrtut.pod"]}

我不知道我能做什么,因为我需要用 QString 解析我的 json 以获得 QJsonDocument 和 QJsonObject。

我尝试了很多东西,比如 QNetworkAccessManager

或者(理解和调试的丑陋事物)像: Curl external

谢谢

您是否使用 qDebug() 作为 stdout 输出?这不是它的用途。

以debug格式显示多种类型的当前内容。对于 QString,它表示引号中带有特定字符的字符串 - 包括双引号 - 用 \ 转义。这并不意味着字符串本身包含转义数据。只有 QDebug.

才会这样呈现给你