开发者

Problem decoding a JSON string containing "’"

开发者 https://www.devze.com 2023-01-12 23:30 出处:网络
My string like this: { \"key\": \"value’s\", \"key2\": \"value\" } I use开发者_开发问答 json_decode() PHP 5 and class Services_Json for PHP 4 and get nothing when contain \"’\".

My string like this:

{
  "key": "value’s",
  "key2": "value"
}

I use开发者_开发问答 json_decode() PHP 5 and class Services_Json for PHP 4 and get nothing when contain "". What is solution?


Most likely your input string isn't properly utf-8 encoded.

http://docs.php.net/json_decode says:

This function only works with UTF-8 encoded data.
And when I feed it your string utf-8 encoded (i.e. when ’ is encoded as the three-byte-sequence E2 80 99 instead of 92 in latin1) the result is

object(stdClass)#1 (2) {
  ["key"]=>
  string(9) "value’s"
  ["key2"]=>
  string(5) "value"
}

(using php 5.3.3/winxp)

0

精彩评论

暂无评论...
验证码 换一张
取 消