本帖最后由 bhjl2006ok 于 2015-01-04 16:17:28 编辑

解决方案 »

  1.   

    $s = '[{"id":"9","model":"A2","quantity":"1"},{"id":"8","model":"A1","quantity":"1"}]';
    print_r(json_decode($s, 1));Array
    (
        [0] => Array
            (
                [id] => 9
                [model] => A2
                [quantity] => 1
            )    [1] => Array
            (
                [id] => 8
                [model] => A1
                [quantity] => 1
            ))
    没有问题你应该贴出未经处理的原始数据,才可能发现问题
    比如数据库取出的是 $ship_info["product_info"]
    那就 echo base64_encode($ship_info["product_info"]);
    贴出结果
      

  2.   

    下面是显示的结果
    echo base64_encode($ship_info["product_info"]);W3smcXVvdDtpZCZxdW90OzomcXVvdDs5JnF1b3Q7LCZxdW90O21vZGVsJnF1b3Q7OiZxdW90O0EyJnF1b3Q7LCZxdW90O3F1YW50aXR5JnF1b3Q7OiZxdW90OzEmcXVvdDt9LHsmcXVvdDtpZCZxdW90OzomcXVvdDs4JnF1b3Q7LCZxdW90O21vZGVsJnF1b3Q7OiZxdW90O0ExJnF1b3Q7LCZxdW90O3F1YW50aXR5JnF1b3Q7OiZxdW90OzEmcXVvdDt9XQ==echo $ship_info["product_info"];
    [{"id":"9","model":"A2","quantity":"1"},{"id":"8","model":"A1","quantity":"1"}]
      

  3.   

    原始数据:
    [{"id":"9","model":"A2","quantity":"1"},{"id":"8","model":"A1","quantity":"1"}]
    $product_info=str_replace('"','"',$ship_info["product_info"]);//替换转义字符 (双引号)
    上面的数据是经这个替换的。
    但为什么JSON里只有一级数据的时候是正常的呢。
      

  4.   

    $product_info=str_replace('"','"',$ship_info["product_info"]);
    这行代码的问题。" 这样写一组数据的时候可以用。多组为空
    " 这样写多组的正常组的。单组的为空
      

  5.   

    请先看清楚你的真实数据再考虑写代码!$s = 'W3smcXVvdDtpZCZxdW90OzomcXVvdDs5JnF1b3Q7LCZxdW90O21vZGVsJnF1b3Q7OiZxdW90O0EyJnF1b3Q7LCZxdW90O3F1YW50aXR5JnF1b3Q7OiZxdW90OzEmcXVvdDt9LHsmcXVvdDtpZCZxdW90OzomcXVvdDs4JnF1b3Q7LCZxdW90O21vZGVsJnF1b3Q7OiZxdW90O0ExJnF1b3Q7LCZxdW90O3F1YW50aXR5JnF1b3Q7OiZxdW90OzEmcXVvdDt9XQ==';
    $s = base64_decode($s);
    $s = html_entity_decode($s);
    $s = html_entity_decode($s); //多做几遍也无所谓,关键是要一层一层的将 html 转义转回来
    echo $s;
    print_r(json_decode($s, 1));[{"id":"9","model":"A2","quantity":"1"},{"id":"8","model":"A1","quantity":"1"}]
    Array
    (
        [0] => Array
            (
                [id] => 9
                [model] => A2
                [quantity] => 1
            )    [1] => Array
            (
                [id] => 8
                [model] => A1
                [quantity] => 1
            ))