2

I have on DB2 table that stores one Json string on one of the fields and I need to get this value and display on a browser, so this is here my problem begins...

Some json string has German chars that for some reason only when I execute the php from a browser gets error 5 on json_last_error(), if I execute the same script on terminal, it execute with success.

Another thing is, if I get the same json string, and put direct on a var instead of get the var from DB2 using db2_exec() it works too.

so I built one script to test, and here my tests:

EXECUTING FROM TERMINAL:

message to be decoded:

From DB:
{"location":" Österr","street1":"straße"}

From var:
{"location":" Österr","street1":"straße"}

-------------------------------------------------------------

Json Decode From Var...
stdClass Object
(
    [location] =>  Österr
    [street1] => straße
)


-------------------------------------------------------------

Json Error Checking Json Decode Var...

 - No errors

-------------------------------------------------------------

Json Decode From DB...
stdClass Object
(
    [location] =>  Österr
    [street1] => straße
)


-------------------------------------------------------------

Json Error Checking Json Decode DB...

 - No errors

EXECUTING FROM BROWSER:

Execute from browser

I already tried:

utf8_encode() - but this does nothing and the var still the same.

iconv - get an error saying that there is one invalid char.

I am running out of options to solve this.. I really need help on this.

Thank you.

Mykola
  • 3,343
  • 6
  • 23
  • 39
Bruno
  • 63
  • 1
  • 7
  • Those are in no way validly encoded "German characters". `json_decode` fails because it needs UTF-8; and looking at what you show I can't fault it, because you're giving it *some garbage* in who knows what encoding. An ß looks like ß in properly handled UTF-8, not "ß". Please peruse the duplicate and start by handing UTF-8 properly [front to back](http://kunststube.net/frontback). – deceze Jan 27 '16 at 14:59
  • mb_detect_encoding() returns that the string is UTF-8.. – Bruno Jan 27 '16 at 17:24
  • I cant find the same question as mine, can you send me the link of the question? – Bruno Jan 27 '16 at 17:24
  • Not the *same* question as yours, but a question about using UTF-8 all the way through. (At the very top of your question, in case you missed it.) Cover your basics there first; at the moment it's completely unproductive to speculate about what encoding you're using incorrectly where when all we see is garbage characters to begin with. – deceze Jan 28 '16 at 10:31

0 Answers0