views:

268

answers:

2

Hello,

Can anyone help me with this one

I have this query and only after adding the last one wich is indexed against the euro I get invalid json.

$url = 'http://www.google.com/finance/info?client=ig&q=goog,yhoo,AMS:TOM2';
$response= json_decode($response,true); 

The only thing different if I directly echo the output is the questionmark in the json.

What would I use to replace the eurosign in the json return?, - and hopefully that will solve it.

thanks in adv, Richard

+2  A: 

The JSON is valid ISO-8859-1, or Latin1. If your application is using some other encoding, say UTF-8, you need to convert the encoding of the response from Latin1 to UTF-8.

Jaanus
Thank you, and no,I use decode.I get the response from curl, I stript it from the forward slashes at the beginning and then I decode it. Then I loop threw the arrays.Except when I add the third stock, it returns null. I am going to try it with an american stock to try to pinpoint the problem exactly.
Richard
this worked utf8_encode($response)I read the docs of json_decode a little more and there I saw what you ment. Although I would like to know where al those differences are coming from. But thanks for the solution.
Richard
+1  A: 

json_encode and json_decode expect in/output to be utf-8. PHP defaults to use iso-8859-1 as charset. So you may have to convert. (Note that the euro sign doesn't exist in iso-8859-1).

troelskn