json problem? qx.io.Json

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

json problem? qx.io.Json

Petr Kobalíček
Hi again :)

I have problem with qx.io.Json.parse()

qx.io.Json.parse('{"result": {"files": [["AUTOEXEC.BAT", 0, "source\/batch", "", ""], ["boot.ini", 250, "document\/ini", "", ""], ["Bootfont.bin", 4952, "", "", ""], ["bootsect.lnx", 512, "", "", ""], ["CONFIG.SYS", 0, "windows\/system-file", "", ""], ["IO.SYS", 0, "windows\/system-file", "", ""], ["MSDOS.SYS", 0, "windows\/system-file", "", ""], ["NTDETECT.COM", 47564, "windows\/executable", "", ""], ["ntldr", 250048, "", "", ""]], "dirs": ["..", "cygwin", "Documents and Settings", "Download", "Games", "MSOCache", "My", "Program Files", "RECYCLER", "School", "Shared", "System Volume Information", "Upload", "WINDOWS"], "path": "\/"}}');

This JSON string was generated by python simplejson package and I thing that's correct. If I use eval, everything is ok.

Where is the problem ?

NOTE: qooxdoo version 0.7.3, firefox3, ie7

Error: Could not parse JSON string!

Source code of parse()

    /**
     * Parse a JSON text, producing a JavaScript value.
     * It returns false if there is a syntax error.
     *
     * @type static
     * @param text {String} JSON string
     * @return {Object} Returns the object
     * @throws an error if the text could not be parsed or evaluated
     */
    parse : function(text)
    {
      // here is something wrong ?
      if (!(/[^,:{}\[\]0-9.\-+Eaeflnr-u \n\r\t]/.test(text.replace(/"(\\.|[^"\\])*"/g, "")))) {
        throw new Error("Could not parse JSON string!");
      }

      try {
        return eval("(" + text + ")");
      } catch(ex) {
        throw new Error("Could not evaluate JSON string: " + ex.message);
      }
    },

-------------------------------------------------------------------------
Sponsored by: SourceForge.net Community Choice Awards: VOTE NOW!
Studies have shown that voting for your favorite open source project,
along with a healthy diet, reduces your potential for chronic lameness
and boredom. Vote Now at http://www.sourceforge.net/community/cca08
_______________________________________________
qooxdoo-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel
Reply | Threaded
Open this post in threaded view
|

Re: json problem? qx.io.Json

Petr Kobalíček
Oh and documentation says that it will return false if it can parse it, but exception is always thrown :)

2008/7/2 petr kobalicek <[hidden email]>:
Hi again :)

I have problem with qx.io.Json.parse()

qx.io.Json.parse('{"result": {"files": [["AUTOEXEC.BAT", 0, "source\/batch", "", ""], ["boot.ini", 250, "document\/ini", "", ""], ["Bootfont.bin", 4952, "", "", ""], ["bootsect.lnx", 512, "", "", ""], ["CONFIG.SYS", 0, "windows\/system-file", "", ""], ["IO.SYS", 0, "windows\/system-file", "", ""], ["MSDOS.SYS", 0, "windows\/system-file", "", ""], ["NTDETECT.COM", 47564, "windows\/executable", "", ""], ["ntldr", 250048, "", "", ""]], "dirs": ["..", "cygwin", "Documents and Settings", "Download", "Games", "MSOCache", "My", "Program Files", "RECYCLER", "School", "Shared", "System Volume Information", "Upload", "WINDOWS"], "path": "\/"}}');

This JSON string was generated by python simplejson package and I thing that's correct. If I use eval, everything is ok.

Where is the problem ?

NOTE: qooxdoo version 0.7.3, firefox3, ie7

Error: Could not parse JSON string!

Source code of parse()

    /**
     * Parse a JSON text, producing a JavaScript value.
     * It returns false if there is a syntax error.
     *
     * @type static
     * @param text {String} JSON string
     * @return {Object} Returns the object
     * @throws an error if the text could not be parsed or evaluated
     */
    parse : function(text)
    {
      // here is something wrong ?
      if (!(/[^,:{}\[\]0-9.\-+Eaeflnr-u \n\r\t]/.test(text.replace(/"(\\.|[^"\\])*"/g, "")))) {
        throw new Error("Could not parse JSON string!");
      }

      try {
        return eval("(" + text + ")");
      } catch(ex) {
        throw new Error("Could not evaluate JSON string: " + ex.message);
      }
    },


-------------------------------------------------------------------------
Sponsored by: SourceForge.net Community Choice Awards: VOTE NOW!
Studies have shown that voting for your favorite open source project,
along with a healthy diet, reduces your potential for chronic lameness
and boredom. Vote Now at http://www.sourceforge.net/community/cca08
_______________________________________________
qooxdoo-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel
Reply | Threaded
Open this post in threaded view
|

Re: json problem? qx.io.Json

Helder Magalhães
In reply to this post by Petr Kobalíček


petr kobalicek-2 wrote:

>
> qx.io.Json.parse('{"result": {"files": [["AUTOEXEC.BAT", 0,
> "source\/batch",
> "", ""], ["boot.ini", 250, "document\/ini", "", ""], ["Bootfont.bin",
> 4952,
> "", "", ""], ["bootsect.lnx", 512, "", "", ""], ["CONFIG.SYS", 0,
> "windows\/system-file", "", ""], ["IO.SYS", 0, "windows\/system-file", "",
> ""], ["MSDOS.SYS", 0, "windows\/system-file", "", ""], ["NTDETECT.COM",
> 47564, "windows\/executable", "", ""], ["ntldr", 250048, "", "", ""]],
> "dirs": ["..", "cygwin", "Documents and Settings", "Download", "Games",
> "MSOCache", "My", "Program Files", "RECYCLER", "School", "Shared", "System
> Volume Information", "Upload", "WINDOWS"], "path": "\/"}}');
>

Copy and pasting the text into JSONlint [1] outputs it as "Valid JSON" also.

Hope this helps,

 Helder Magalhães

[1] http://www.jsonlint.com/
--
View this message in context: http://www.nabble.com/json-problem--qx.io.Json-tp18238196p18239493.html
Sent from the qooxdoo-devel mailing list archive at Nabble.com.


-------------------------------------------------------------------------
Sponsored by: SourceForge.net Community Choice Awards: VOTE NOW!
Studies have shown that voting for your favorite open source project,
along with a healthy diet, reduces your potential for chronic lameness
and boredom. Vote Now at http://www.sourceforge.net/community/cca08
_______________________________________________
qooxdoo-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel
Reply | Threaded
Open this post in threaded view
|

Re: json problem? qx.io.Json

thron7
In reply to this post by Petr Kobalíček
This is a good one. I filed a bug
http://bugzilla.qooxdoo.org/show_bug.cgi?id=1027 . Some basic fix has
been applied, in both trunk and legacy_0_7_x (r14263).

If you are sticking with 0.7.3, you might want to draw the version from
legacy_0_7_x into your own code (it's short).

Thomas

> Hi again :)
>
> I have problem with qx.io.Json.parse()
>
> qx.io.Json.parse('{"result": {"files": [["AUTOEXEC.BAT", 0,
> "source\/batch", "", ""], ["boot.ini", 250, "document\/ini", "", ""],
> ["Bootfont.bin", 4952, "", "", ""], ["bootsect.lnx", 512, "", "", ""],
> ["CONFIG.SYS", 0, "windows\/system-file", "", ""], ["IO.SYS", 0,
> "windows\/system-file", "", ""], ["MSDOS.SYS", 0,
> "windows\/system-file", "", ""], ["NTDETECT.COM
> <http://NTDETECT.COM>", 47564, "windows\/executable", "", ""],
> ["ntldr", 250048, "", "", ""]], "dirs": ["..", "cygwin", "Documents
> and Settings", "Download", "Games", "MSOCache", "My", "Program Files",
> "RECYCLER", "School", "Shared", "System Volume Information", "Upload",
> "WINDOWS"], "path": "\/"}}');
>
> This JSON string was generated by python simplejson package and I
> thing that's correct. If I use eval, everything is ok.
>
> Where is the problem ?
>
> NOTE: qooxdoo version 0.7.3, firefox3, ie7
>
> Error: Could not parse JSON string!
>
> Source code of parse()
>
>     /**
>      * Parse a JSON text, producing a JavaScript value.
>      * It returns false if there is a syntax error.
>      *
>      * @type static
>      * @param text {String} JSON string
>      * @return {Object} Returns the object
>      * @throws an error if the text could not be parsed or evaluated
>      */
>     parse : function(text)
>     {
>       // here is something wrong ?
>       if (!(/[^,:{}\[\]0-9.\-+Eaeflnr-u
> \n\r\t]/.test(text.replace(/"(\\.|[^"\\])*"/g, "")))) {
>         throw new Error("Could not parse JSON string!");
>       }
>
>       try {
>         return eval("(" + text + ")");
>       } catch(ex) {
>         throw new Error("Could not evaluate JSON string: " + ex.message);
>       }
>     },
> ------------------------------------------------------------------------
>
> -------------------------------------------------------------------------
> Sponsored by: SourceForge.net Community Choice Awards: VOTE NOW!
> Studies have shown that voting for your favorite open source project,
> along with a healthy diet, reduces your potential for chronic lameness
> and boredom. Vote Now at http://www.sourceforge.net/community/cca08
> ------------------------------------------------------------------------
>
> _______________________________________________
> qooxdoo-devel mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel
>  


-------------------------------------------------------------------------
Sponsored by: SourceForge.net Community Choice Awards: VOTE NOW!
Studies have shown that voting for your favorite open source project,
along with a healthy diet, reduces your potential for chronic lameness
and boredom. Vote Now at http://www.sourceforge.net/community/cca08
_______________________________________________
qooxdoo-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel