PHP and JSON problem

Associate
Joined
28 Nov 2004
Posts
1,237
Location
Birmingham
Hi all,
I'm working with the Last.fm API at the moment and i'm having trouble with a block of text and JSON.
Basically, I call the API using a page similar to:
http://www.scgough.co.uk/include/lastfm/jsontest.php?artist=nirvana

this brings back the artist name, mbid, url, image url, summary and description.

as you can see if you 'view source', i want to return this as a json string to be processed in javascript. without the summary and descrption, all is ok but with it, i get an invalid JSON object back according to javascript.

I'm escaping the text with:
PHP:
$output.=",summary : ".chr(34).addslashes(htmlspecialchars($bio->summary)).chr(34);
$output.=",description : ".chr(34).addslashes(htmlspecialchars($bio->content)).chr(34);
but i'm obviously missing something. Any ideas?!? :)
 
cheers pho. got that sorted but to get around the main problem i had to use base64 encoding/decoding on the bulk text. it works now.
thought i'd post the answer on here in case anyone else bumps into a similar situation :)
 
Back
Top Bottom