代码之家  ›  专栏  ›  技术社区  ›  sree

在php中解码包含+符号的长字符串(超过1000个字符)的json字符串

  •  0
  • sree  · 技术社区  · 7 年前

    我有一个json字符串,包含像+,-,“,'这样的特殊字符。当我尝试对字符串使用json\u解码时,解码在+符号处中断。+符号后的内容没有解码。

    我的代码如下:

    //Example string
    $str = '{"image":"wo7898Ee/fp+18mtyeex//Z"}';
    $res = json_decode($str, true);
    

    我的输出是打印到/fp。最后一个字符被截断并显示解码输出为。。。

    请帮忙

    1 回复  |  直到 7 年前
        1
  •  1
  •   pr1nc3    7 年前
    $str = '{
        "image": "wo7898Ee/fp+18mtyeex//Z"
    }';
    $res = json_decode($str, true);
    
    print_r($res['image']);
    

    输出为: wo7898Ee/fp+18mtyeex//Z

    推荐文章