Re: Parsing JSON; back-slash problem

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Tue, 2009-12-15 at 06:52 -0500, Andrew Burgess wrote:

> This seems like a pretty basic question, but it has me stumped.
> 
> Here's my scenario: I'm using Douglas Crockford's JSON2.js to parse an
> object in JavaScript, which I then pass to a PHP script to store in a
> file. I use JSON.stringify() on the object, which logs to the console
> as this:
> 
> {"employees":{"data":{"John":{"fname":"John","lname":"Doe","city":"Toronto","country":"Canada"}}}}
> 
> Then I use the jQuery POST function to send it to a PHP script. Before
> doing anything with it in PHP, I log the received value to the
> console, and this is what I get:
> 
> {\"employees\":{\"data\":{\"John\":{\"fname\":\"John\",\"lname\":\"Doe\",\"city\":\"Toronto\",\"country\":\"Canada\"}}}}
> 
> The problem is, when I call the script to retrieve this data from a
> file, JSON.parse can't parse it because of the back-slashes. I'm
> pretty sure my problem is on the PHP side (since it's fine coming out
> of JS); what do I need to do to fix this? is a preg_replace enough?
> 


Turn off magic quotes, as it looks like they are enabled on your server.
You can turn them off from the .htaccess file if you don't have access
to the php.ini

Thanks,
Ash
http://www.ashleysheridan.co.uk



[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux