问题:json_decode($str)的结果是null,错误结果是4,也就是语法错误。但是不知道哪里的语法错误,找了网上各种方法尝试都没用,最后直接在一个在线json解析网站把字符串丢进去解析就知道哪里出问题了,由于自字符串中有个淘宝链接导致的语法错误,然后换个链接就好了

<?php
    $str = '见附件中内容';
    $result = json_decode($str);
    if(!$result)
    {
        $ret = json_last_error();
        print_r($ret);   //打印为: 4,查错误信息表,可知是语法错误
        
    } else {
      var_dump($result);
    }
?>

字符串内容如下:

[{"product_id":12534665,"tuan_price":120,"tuan_sku_cms_scale":8,"order_limit_num":0,"user_limit_num":0,"module":[{"type":"input","name":"商品标题","comments":"商品标题,5-15个字之间","min_length":"5","max_length":"15","label_1":"","label_2":"","input_key":"title","input_val":"俞兆林瘦身产后收腹连体塑身衣","required":1,"template":"","module_name":"title","err_msg":""},{"type":"input","name":"卖点1","comments":"营销文案,5个文字以内","min_length":0,"max_length":5,"label_1":"","label_2":"","input_key":"sub_desc_1","input_val":"超值108元","required":1,"template":"","module_name":"sub_desc_1","err_msg":""},{"type":"input","name":"卖点2","comments":"营销文案,5个文字以内","min_length":0,"max_length":5,"label_1":"","label_2":"","input_key":"sub_desc_2","input_val":"塑身燃脂","required":0,"template":"","module_name":"sub_desc_2","err_msg":""},{"type":"input","name":"卖点3","comments":"营销文案,5个文字以内","min_length":0,"max_length":5,"label_1":"","label_2":"","input_key":"sub_desc_3","input_val":"收腹提臀","required":0,"template":"","module_name":"sub_desc_3","err_msg":""},{"type":"input","name":"商品站外链接","comments":"","min_length":"","max_length":"","label_1":"","label_2":"","input_key":"outer_link","input_val":"https://detail.tmall.com/item.htm?spm=a220o.1000855.1998025129.3.7fab49231rhk2Y&pvid=d6619c06-2bb8-4ea1-a512-858b8b27d239&pos=3&acm=03054.1003.1.2768562&id=596662639804&scm=1007.16862.95220.23864_0_0&utparam={"x_hestia_source":"23864","x_object_type":"item","x_mt":0,"x_src":"23864","x_pos":3,"x_pvid":"d6619c06-2bb8-4ea1-a512-858b8b27d239","x_object_id":596662639804}&skuId=4313871398448","required":1,"template":"","info_bottom":"<div  16px;padding-left: 92px;\"><span   20px;\">请填写该商品在淘宝或天猫上的商详页链接,链接正确,才能审核通过。</span></div>","module_name":"outer_link","fold":true,"err_msg":""},{"type":"radio_promotion_play","name":"促销玩法","disable_edit":false,"checked_map":{"none":"不参加","rebate":"限量折扣","discount":"限量立减","present":"买就送","share_coupon":"分享领券","swell_coupon":"膨胀券"},"checked_info_bottom_map":{"none":"","rebate":"<div  16px;padding-left: 92px;\">\n                           <p   20px;\">勾选此项,将视为您承诺为符合条件的用户提供折扣优惠</p>\n                           <p   20px;\">根据您的配置,支付时间靠前的用户将享受折扣优惠,<span  #e72645\">符合条件的用户每次活动可享受一次(以用户ID为准)</span>,优惠名额与优惠力度将由您来定义。</p>\n                           <p   20px;\">测款期间与上首页期间均会生效,且优惠名额与优惠力度需要完全相同</p>\n                           </div>","discount":"<div  16px;padding-left: 92px;\">\n                           <p   20px;\">勾选此项,将视为您承诺为符合条件的用户提供立减优惠</p>\n                           <p   20px;\">根据您的配置,支付时间靠前的用户将享受立减优惠,<span  #e72645\">符合条件的用户每次活动可享受一次(以用户ID为准)</span>,立减名额与优惠力度将由您来定义。</p>\n                           <p   20px;\">测款期间与上首页期间均会生效,且立减名额与优惠力度需要完全相同</p>\n                           </div>","present":"<div  16px;padding-left: 92px;\">\n                           <p   20px;\">勾选此项,将视为您承诺为符合条件的订单提供合格且足量的赠品</p>\n                           <p   20px;\">根据您的配置,支付时间靠前的订单将会获得由您提供的赠品,我们规定订单一旦符合赠送要求,<span  #e72645\">赠品件数需与该订单包含的商品件数相同</span>,赠品商品与数量将由您来定义。</p>\n                           </div>","share_coupon":"<div  16px;padding-left: 92px;\">\n                            <p   20px;\">勾选此项,同时也将视为您承诺为符合条件的用户提供领券立减的服务</p>\n                            <p   20px;\">配置分享领券将能为商品提供更大的流量曝光,用户分享商品后能得到此商品的优惠券,并在购买此商品时享受优惠金额!</p>\n                            </div>","swell_coupon":"<div  16px;padding-left: 92px;\">\n                            <p   20px;\">勾选此项,同时也将视为您承诺为符合条件的用户提供膨胀券的服务</p>\n                            <p   20px;\">配置分享领券将能为商品提供更大的流量曝光,用户分享商品后能得到此商品的优惠券,并在购买此商品时享受优惠金额!</p>\n                            </div>"},"input_key":"promotion_play_radio","input_val":"none","template":"","module_name":"promotion_play_radio","fold":true,"err_msg":""},{"type":"input_promotion_discount","name":"促销条件","required":1,"checked_key":"promotion_discount","label_1":"限量秒杀前","label_2":"名支付买家下单立减","label_3":"元","input_key_1":"promotion_discount_tuan_limit_num","input_key_2":"promotion_discount_tuan_money","input_val_1":"","input_val_2":"","label_4":"首页商品前","label_5":"名支付买家下单立减","label_6":"元","info_bottom":"","is_checked":[],"template":"","module_name":"promotion_discount","fold":true,"err_msg":"","err_msg_1":"","err_msg_2":"","input_promotion_discount_value":"none"},{"type":"input_promotion_present","name":"促销条件","required":1,"checked_key":"promotion_present","label_1":"赠品名称:","input_key_1":"promotion_present_name","input_val_1":"","min_length":2,"max_length":10,"label_2":"件数:","input_key_2":"promotion_present_num","input_val_2":"","label_3":"件","info_bottom":"","is_checked":[],"template":"","module_name":"promotion_present","fold":true,"err_msg":"","err_msg_1":"","err_msg_2":"","input_promotion_present_value":"none"},{"type":"input_promotion_share_coupon","name":"促销条件","required":1,"checked_key":"promotion_share_coupon","label_1":"店铺券ID:","input_key_1":"promotion_share_coupon_id","input_val_1":"","min_length":2,"max_length":10,"module_name":"promotion_share_coupon","fold":true,"err_msg":"","err_msg_1":"","couponValue":"","input_promotion_share_coupon_value":"none"},{"type":"input_promotion_swell_coupon","name":"膨胀券配置","required":1,"checked_key":"promotion_swell_coupon","label_1":"膨胀前券名称","label_2":"券面额","label_3":"发放张数","label_4":"膨胀后券名称","label_5":"券面额","label_6":"发放张数","input_key_1":"swell_coupon_name_1","input_key_2":"swell_coupon_val_1","input_key_3":"swell_coupon_num_1","input_val_1":"","input_val_2":"","input_val_3":"","input_key_4":"swell_coupon_name_2","input_key_5":"swell_coupon_val_2","input_key_6":"swell_coupon_num_2","input_val_4":"","input_val_5":"","input_val_6":"","module_name":"promotion_swell_coupon","fold":true,"err_msg":"","err_msg_1":"","input_promotion_swell_coupon_value":"none"},{"type":"input_promotion_rebate","name":"促销条件","required":1,"checked_key":"promotion_rebate","label_1":"限量秒杀前","label_2":"名支付买家 享受","label_3":"折","input_key_1":"promotion_rebate_tuan_limit_num","input_key_2":"promotion_rebate_tuan_discount","input_val_1":"","input_val_2":"","label_4":"首页商品前","label_5":"名支付买家 享受","label_6":"折","info_bottom":"","is_checked":[],"template":"","module_name":"promotion_rebate","fold":true,"err_msg":"","err_msg_1":"","err_msg_2":"","input_promotion_rebate_value":"none"}],"sku":[{"id":"234242408","sku_price":120,"sku_cms_scale":8},{"id":"234242409","sku_price":120,"sku_cms_scale":8},{"id":"234242410","sku_price":120,"sku_cms_scale":8},{"id":"234242411","sku_price":120,"sku_cms_scale":8},{"id":"234242412","sku_price":120,"sku_cms_scale":8},{"id":"234242413","sku_price":120,"sku_cms_scale":8},{"id":"234242414","sku_price":120,"sku_cms_scale":8},{"id":"234242415","sku_price":120,"sku_cms_scale":8},{"id":"234242416","sku_price":120,"sku_cms_scale":8},{"id":"234242417","sku_price":120,"sku_cms_scale":8},{"id":"234242418","sku_price":120,"sku_cms_scale":8},{"id":"234242419","sku_price":120,"sku_cms_scale":8},{"id":"234242421","sku_price":120,"sku_cms_scale":8},{"id":"234242423","sku_price":120,"sku_cms_scale":8},{"id":"234242424","sku_price":120,"sku_cms_scale":8},{"id":"234242425","sku_price":120,"sku_cms_scale":8},{"id":"234242426","sku_price":120,"sku_cms_scale":8},{"id":"234242427","sku_price":120,"sku_cms_scale":8},{"id":"234242428","sku_price":120,"sku_cms_scale":8},{"id":"234242429","sku_price":120,"sku_cms_scale":8}],"tuan_limit_num":100}]

hizengzeng
177 声望10 粉丝

hizengzeng