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

从woomerce负载中提取对象并从字符串中移除反斜杠

  •  0
  • Gracie  · 技术社区  · 6 年前

    我试图访问AWS Lambda中woomerce webhook负载中的对象(tmp_name)。此时,我可以输出“行项目”,其中:

    exports.handler = (event, context, callback, err) => {
        callback(null, event.line_items);
        if (err) console.log('JSON Pass Fail');  // an error occurred
        else     console.log(event.order_key); // successful response
    };
    

    当我试图深入到事件数据时,它会以null的形式运行,例如

    callback(null,event.line_items.meta_data.value.tmp_name);

    我也试过用0和[0]访问数组,但没有任何乐趣。

    最后,如果我可以访问文件路径,我需要去掉后拉,使它看起来像一个正确的文件路径。我已经拿到了 string.replace(/\\\//g, "/");

    有人能帮我把这个拼起来吗?

    {
    "line_items": [
        {
        "id": 2,
        "name": "Audio 5",
        "product_id": 15,
        "variation_id": 0,
        "quantity": 1,
        "tax_class": "",
        "subtotal": "10.00",
        "subtotal_tax": "0.00",
        "total": "10.00",
        "total_tax": "0.00",
        "taxes": [
    
        ],
        "meta_data": [
            {
            "id": 20,
            "key": "_wcj_product_input_fields_global_1",
            "value": {
                "name": "Aaron Ramsey's departure from Arsenal to Juventus.mp3",
                "type": "audio\/mp3",
                "tmp_name": "\/home\/site\/public_html\/wp-content\/uploads\/woocommerce_uploads\/wcj_uploads\/input_fields_uploads\/21.mp3",
                "error": 0,
                "size": 4943085,
                "wcj_type": "file"
            }
            }
        ],
        "sku": "",
        "price": 10
        }
    ],
    "tax_lines": [
    
    ],
    "shipping_lines": [
    
    ],
    "fee_lines": [
    
    ],
    "coupon_lines": [
    
    ],
    "refunds": [
    
    ]
    }
    
    0 回复  |  直到 6 年前