rlerdorf / opcache-status

A one-page opcache status page
1.56k stars 377 forks source link

Slashes problem in Windows #46

Open springimport opened 7 years ago

springimport commented 7 years ago

Currently I use the windows 10 x64 OpenServer and I have a problem with slashes in JSON.parse().

VM444:1 Uncaught SyntaxError: Unexpected token D in JSON at position 10
    at JSON.parse (<anonymous>)
    at (index):477

Page source:

root = JSON.parse('{"name":"\\D:\\OpenServer\\domains\\opcache-status","children":[{"name":"vendor","children":[{"name":"rlerdorf","children":[{"name":"opcache-status","children":[{"name":"opcache.php","size":54152}]}]}]},{"name":"index.php","size":712}]}');

My solution:

root = JSON.parse('<?php echo json_encode(str_replace('\\', '/', $dataModel->getD3Scripts())); ?>');

Result:

root = JSON.parse('{"name":"\/D:\/OpenServer\/domains\/opcache-status","children":[{"name":"vendor","children":[{"name":"rlerdorf","children":[{"name":"opcache-status","children":[{"name":"opcache.php","size":54464}]}]}]},{"name":"index.php","size":712}]}');