JSON.stringify problem



  • I use QWebEngineView to load a simple webpage:
    view = new QWebEngineView(this);
    view->load(QUrl("file:///index1.html"));
    The web page is:
    <!doctype html>
    <html>
    <meta charset="utf-8">
    <head>
    </head>
    <body>

    <script>
    var par={var1:"123","var2":456};
    alert(JSON.stringify(par));
    </script>
    </body>
    </html>

    The alert window is:
    0_1517382485078_96562f06-6d8d-4978-afe6-3fd5869ac263-图片.png

    Note that all the quote marks in the object are encoded as html entities How could this happen? How to get the orignal " not html entities. The Qt version I use is Qt 5.10.0 MSVC2017 64 bit.

    Thanks!



  • @yetanotherqtfan
    Don't understand what your problem/issue/question is? That output is the JSON stringification of the object. All that stringify should gurantee is that the resulting string can be passed around safely, and that JSON.parse(JSON.stringify(obj)) should return an object that is the same JS object as you started with. So what does JSON.parse() return in your case?

    &quot; is the HTML entitization of the " character.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.