QJsonDocument: JSON.parse() equivalence
-
Hello everyone.
Because
QJsonDocument::fromJSON()
supports object and array types only,- number values:
1
,2.3
- boolean values:
true
,false
- string values:
"foo"
,"bar"
- null value:
null
strings above are recognized as invalid JSON documents.
Also, instantiating
QJSEngine
and callJSON.parse()
with string is not considered because it's too much overhead.So, I wonder does Qt has a simple solution that convert a string to JS value like
JSON.parse()
do?Any ideas are welcome :)
- number values:
-
@VRonin Hi, thank you for the reply.
The values are from XML files and there're some text values which types are not declared in the document but must be one of the valid JS values.
I don't really like to use
QString
based methods to parse them manually, not just I don't know the exact type of a value, but also there're some details behind theJSON.parse()
, such as extra spaces, precision problems, etc.