Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    New to the CF scene
    Join Date
    Apr 2009
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question What's wrong with this JSON string?

    Here's the string:

    {"bucket":"dhat-groups-3", "key":"teachings/00little01.txt", "etag":"0c44405e7efa6d576bc7809646418000"}

    I'm getting an "invalid JSON string" message from the YAHOO.lang.JSON.parse() method. (See http://developer.yahoo.com/yui/docs/JSON.html) The full error message is:

    Invalid JSON string returned from the success_action_redirect URL:
    <pre>{"bucket":"dhat-groups-3", "key":"teachings/00little02.txt", "etag":"5592219e321dec57dbf34678a181839f"}</pre>

    As far as I can tell, this string satisfies the syntax at http://www.json.org/.

    Quoting the "/" in the "key" entry, so the string is...

    {"bucket":"dhat-groups-3", "key":"teachings\/00little02.txt", "etag":"5592219e321dec57dbf34678a181839f"}

    ...gets the same error.

    This is my first venture into JSON, so I hope there's something that my untrained eyes are missing.

    ~ TIA
    ~ Ken

  • #2
    bdl
    bdl is offline
    Regular Coder
    Join Date
    Apr 2007
    Location
    Camarillo, CA US
    Posts
    590
    Thanks
    4
    Thanked 83 Times in 82 Posts
    By my eye and by the results at jsonlint.com, that's valid JSON. But, where does it come from? Is it being dynamically returned from a server-side process?

    One thing to consider when returning JSON is the Content-Type of the returning object string.

  • #3
    New to the CF scene
    Join Date
    Apr 2009
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question

    Thanks, bdl, for your quick response.

    Yes, it's being returned from a server Python script.

    I don't know if this matters, but I'm trying to adapt a PHP-based scheme for uploading to Amazon S3 so it works in my Python environment. The scheme is the one at http://developer.amazonwebservices.c...xternalID=1618.

    ~ Ken

  • #4
    Senior Coder rnd me's Avatar
    Join Date
    Jun 2007
    Location
    Urbana
    Posts
    4,401
    Thanks
    11
    Thanked 595 Times in 575 Posts
    does it work with eval? if yes, it looks like yahoo's parser needs more work.

    i'll bet it based on the crockford JSON.parse, which i know has a one to two minor issues last i checked ( a while ago).
    Last edited by rnd me; 04-24-2009 at 08:42 PM.
    my site (updated 13/9/26)
    BROWSER STATS [% share] (2014/9/03) IE7:0.1, IE8:4.6, IE11:9.1, IE9:3.1, IE10:3.0, FF:17.2, CH:46, SF:11.4, NON-MOUSE:38%

  • #5
    New to the CF scene
    Join Date
    Apr 2009
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I've found and (in a klunky way) solved the problem. When my server-side Python script returns the string, something somewhere is wrapping it in "<pre>" tags.

    So the klunky solution was to add a line to the Javascript that strips these tags:

    var responseText = responseText.substring('<pre>'.length, responseText.length - '</pre>'.length)

    Of course, this solution collapses if that something somewhere ever decides to stop wrapping the string in <pre> tags. But that's a problem for another day.

  • #6
    Senior Coder rnd me's Avatar
    Join Date
    Jun 2007
    Location
    Urbana
    Posts
    4,401
    Thanks
    11
    Thanked 595 Times in 575 Posts
    Quote Originally Posted by kenatsun View Post
    Of course, this solution collapses if that something somewhere ever decides to stop wrapping the string in <pre> tags. But that's a problem for another day.
    well, use replace instead of trim, and itt'l work with or without the pre tagsl:

    Code:
    var responseText = responseText.replace(/^\<pre\>,"").replace(/\<\/pre\>/, "");
    my site (updated 13/9/26)
    BROWSER STATS [% share] (2014/9/03) IE7:0.1, IE8:4.6, IE11:9.1, IE9:3.1, IE10:3.0, FF:17.2, CH:46, SF:11.4, NON-MOUSE:38%

  • #7
    New to the CF scene
    Join Date
    Apr 2009
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    That's better. Had to tweak it a bit, thus:

    responseText = responseText.replace(/^\<pre\>/, "").replace(/\<\/pre\>$/, "");

    ~ Thanks
    ~ Ken


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •