从Woocommerce有效内容中提取对象并从字符串中删除反斜杠

时间:2019-01-23 13:18:06

标签: javascript json regex woocommerce aws-lambda

我正在尝试访问AWS Lambda中Woocommerce Webhook有效负载内的对象(tmp_name)。目前,我可以使用以下命令输出“订单项”:

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

当我尝试更深入地研究事件数据时,它作为null运行,例如

string.replace(/\\\//g, "/");

我尝试也不用高兴地用0和[0]访问数组。

最终,如果我可以访问文件路径,则需要去除后缀,使其看起来像是正确的文件路径。我有{ "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": [ ] }

的正则表达式

有人可以帮我把这些放在一起吗?

var myModel = new Model();

            using (var connection = new SqlConnection("Some Connection String"))
            {
                using (var command = new SqlCommand("Some Stored Procedure Name", connection)
                {
                    CommandType = CommandType.StoredProcedure
                })
                {
                    await connection.OpenAsync();

                    //Code Building a list of params

                    using (var reader = await command.ExecuteReaderAsync())
                    {
                        while (await reader.ReadAsync())
                        {
                           //Code Building myModel
                        }
                    }
                }
            }

            return myModel;

0 个答案:

没有答案