-1

I get json string:

$response = '{"retcode":"0","retmsg":"OK","cre_id_enc":"","cre_type":"","fee_type":"1","listid":"1221085301201410240000001024","out_trade_no":"201410246763831","partner":"1221085301","pay_fee":"0","sign":"PTamau\x2BjkynA00cASKJ6Nd3QwFSBP44TKSqmmdCd\x2F\x2B0o8ViSt3fp5vQr0Fc73U42NhtImfnHzbynoUjURiNLW5O4hI61xkG\x2F97JRPRE0nHuvtAumqXfbVCsLveugE52HRZsJvm3EG7pL6GlhYf8ng6qxiUrDyn89PFVZ04Wd8Gk\x3D","total_fee":"1000000","unfreeze_fee":"1000000","user_name_enc":""}';

I use json_decode to convert this string to array,but it return "NULL". I found "sign":"PTamau\x2BjkynA00cASKJ6Nd3QwFSBP44TKSqmmdCd\x2F\x2B0o8ViSt3fp5vQr0Fc73U42NhtImfnHzbynoUjURiNLW5O4hI61xkG\x2F97JRPRE0nHuvtAumqXfbVCsLveugE52HRZsJvm3EG7pL6GlhYf8ng6qxiUrDyn89PFVZ04Wd8Gk\x3D","total_fee":"1000000" can't use json_decode. it contains ASCII code like '\x2F' , '\x2B', '\x3D'. so I try to convert to utf8, like this $response = iconv('ASCII', 'UTF-8//IGNORE', $response);. it's no useful.the response string still contains '\x2F' , '\x2B', '\x3D' and json_decode still return NULL.

someone can help me and forgive me my poor English! Thank you!

GiGi
  • 113
  • 1
  • 12

2 Answers2

1

According to an answer on a very similar question, you need to escape the backslashes:

$json = str_replace( '\x', '\\\\x', $response );

and then pass $json to json_decode

Community
  • 1
  • 1
Vasilis
  • 2,721
  • 7
  • 33
  • 54
0

The issue is the single quotes.

print_r('\x2F');
\x2F
print_r("\x2F");
/

Single quotes will not interpret the backslash sequence, which leaves you with malformed JSON which only allows \\ and \", AFAIK. If you already have the single-backslash string, do what Vasilis says.

Amadan
  • 191,408
  • 23
  • 240
  • 301