Why does Qt reject a valid JSON?

masoud

Using Qt-5.0, I have this JSON string

{"type":"FILE"}

I expected that fromBinaryData accept .toLocal8Bit() of the string as a valid format but it doesn't.

QString j = "{\"type\":\"FILE\"}";

auto doc = QJsonDocument::fromBinaryData(j.toLocal8Bit());

doc.isNull() // It's true, means the entry is not valid

Did I miss something?

Arne Mertz

I have no idea of Qt, so I googled for a second. Here's what I found:

What you have is a string, a text representation. It's not the binary format Qt uses internally. The binary data would not be readable. QJsonDocument::fromBinaryData expects such a binary blob.

What you want to do seems to be achieved with QJsonDocument::fromJson which expects an UTF8-encoded Json string.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Why does Qt reject a valid JSON?

From Java

Why does systemd reject my unit name as 'neither a valid invocation ID nor unit name'?

From Dev

Why does Rust borrow checker reject this code?

From Dev

Why does the Rust borrow checker reject this function?

From Dev

Why does Promise.reject() require a return?

From Dev

Why does expat reject en dash character as invalid?

From Dev

Why does the compiler reject the declaration of a 2D generic array?

From Java

Why does GNAT reject an array type with a default discriminant value?

From Dev

Why does Twilio Twimlbin reject markup that uses voice="alice"?

From Dev

Why does this JavaScript Promise reject() get processed at the result callback?

From Dev

Why does line after return reject() execute in below function?

From Dev

Why does my iptables firewall reject connections to port 1531?

From Dev

Why does telnet on a non existent port not directly reject, but time out?

From Dev

json file does not contain valid JSON

From Dev

Why qt does not read a file

From Dev

Why does @Valid cause a reentrant flush?

From Dev

Why does BindingResult have to follow @Valid?

From Dev

Why does "sbt stage" fail with Not a valid command?

From Dev

Why does the ngModelCtrl.$valid not update?

From Dev

Why is reject not rejecting?

From Dev

Why REJECT slows nmap?

From Dev

Why GraphQL is not designed as a valid json document?

From Dev

Why does Python's `requests` reject my SSL certificate, which browsers accept

From Dev

Why does Format reject procedure address arguments starting with XE4

From Dev

Why does the compiler reject a constant default parameter value with "E2026 Constant expression expected"?

From Dev

Why does ElementTree reject UTF-16 XML declarations with "encoding incorrect"?

From Dev

Why does the AWS cli reject my IAM ARN for not matching the regex/pattern?

From Dev

Why does Spring Data MongoDB reject a field name containing a $ in an aggregation pipeline?

From Dev

Why does Hash#select and Hash#reject pass a key to a unary block?

Related Related

  1. 1

    Why does Qt reject a valid JSON?

  2. 2

    Why does systemd reject my unit name as 'neither a valid invocation ID nor unit name'?

  3. 3

    Why does Rust borrow checker reject this code?

  4. 4

    Why does the Rust borrow checker reject this function?

  5. 5

    Why does Promise.reject() require a return?

  6. 6

    Why does expat reject en dash character as invalid?

  7. 7

    Why does the compiler reject the declaration of a 2D generic array?

  8. 8

    Why does GNAT reject an array type with a default discriminant value?

  9. 9

    Why does Twilio Twimlbin reject markup that uses voice="alice"?

  10. 10

    Why does this JavaScript Promise reject() get processed at the result callback?

  11. 11

    Why does line after return reject() execute in below function?

  12. 12

    Why does my iptables firewall reject connections to port 1531?

  13. 13

    Why does telnet on a non existent port not directly reject, but time out?

  14. 14

    json file does not contain valid JSON

  15. 15

    Why qt does not read a file

  16. 16

    Why does @Valid cause a reentrant flush?

  17. 17

    Why does BindingResult have to follow @Valid?

  18. 18

    Why does "sbt stage" fail with Not a valid command?

  19. 19

    Why does the ngModelCtrl.$valid not update?

  20. 20

    Why is reject not rejecting?

  21. 21

    Why REJECT slows nmap?

  22. 22

    Why GraphQL is not designed as a valid json document?

  23. 23

    Why does Python's `requests` reject my SSL certificate, which browsers accept

  24. 24

    Why does Format reject procedure address arguments starting with XE4

  25. 25

    Why does the compiler reject a constant default parameter value with "E2026 Constant expression expected"?

  26. 26

    Why does ElementTree reject UTF-16 XML declarations with "encoding incorrect"?

  27. 27

    Why does the AWS cli reject my IAM ARN for not matching the regex/pattern?

  28. 28

    Why does Spring Data MongoDB reject a field name containing a $ in an aggregation pipeline?

  29. 29

    Why does Hash#select and Hash#reject pass a key to a unary block?

HotTag

Archive