0

建议一种读取 json 并将其插入 mysql db 的最佳方法。

示例 JSON:

{
    "PaymentOrder": [
        {
            "$": {
                "Id": "83C44C4A-7EFD-491E-913E-007A3598618F",
                "Name": "",
                "OrderNumber": "AH9NZPUI",
                "OrderType": "Recurring",
                "Amount": "1.000000",
                "CouponDiscountAmount": ".000000",
                "ChargeAmount": ".000000",
                "CurrencyCode": "USD",
                "OwnerId": "D9F48450-AB86-4ABE-B9AD-66FE3B7AEFB1",
                "OrderStatus": "Pending",
                "PaymentProcessor": "Global Collect",
                "PaymentMethodType": "Visa",
                "SoftDescriptorText": "CNext_AH9NZPUI",
                "UserPaymentInfoId": "FDD9C487-6F66-4919-B945-766699C9EF1D",
                "IsAuthorization": "1",
                "CreateTime": "2012-07-18T10:21:47.7610377",
                "UpdateTime": "2012-07-18T10:21:47.7610377",
                "IsEnabled": "1",
                "IsDeleted": "0"
            }
        },
        {
            "$": {
                "Id": "03B1600F-F92A-47BA-8B53-00B70A942E43",
                "Name": "",
                "OrderNumber": "3427BBC3",
                "OrderType": "Recurring",
                "Amount": ".000000",
                "CouponDiscountAmount": ".000000",
                "ChargeAmount": ".000000",
                "CurrencyCode": "USD",
                "OwnerId": "9A1186E4-BAC6-43D0-8C6F-B02ECD6544B5",
                "OrderStatus": "Success",
                "PaymentProcessor": "Global Collect",
                "PaymentMethodType": "Visa",
                "SoftDescriptorText": "ComputeNext Inc Order Number - 3427BBC3",
                "UserPaymentInfoId": "142C6B38-A470-40A9-B7A7-1C8CDD6FBD2C",
                "BillingHistoryId": "6BE8DF8E-4C97-492B-9407-38EBA2B942F2",
                "InvoiceDate": "2013-03-26T14:02:07.8570464",
                "IsAuthorization": "0",
                "CreateTime": "2013-03-26T18:08:19.5383118",
                "UpdateTime": "2013-03-26T18:08:19.5695118",
                "IsEnabled": "1",
                "IsDeleted": "0"
            }
        },
        {
            "$": {
                "Id": "8FC1D8EA-C388-4F31-91C7-00CB54C337A4",
                "Name": "",
                "OrderNumber": "YTM8TOKQ",
                "OrderType": "Recurring",
                "Amount": "1.000000",
                "CouponDiscountAmount": ".000000",
                "ChargeAmount": ".000000",
                "CurrencyCode": "USD",
                "OwnerId": "3702AB47-1095-4211-B844-82C47D0D9F6C",
                "OrderStatus": "Failure",
                "PaymentProcessor": "Global Collect",
                "PaymentMethodType": "Visa",
                "SoftDescriptorText": "CNext_YTM8TOKQ",
                "UserPaymentInfoId": "19193F72-14D1-4A72-9676-2493002711ED",
                "TransactionDuration": "0:0:40:809",
                "LastTransactionNumber": "HC0F4CBYMT14QP3",
                "IsAuthorization": "1",
                "CreateTime": "2012-07-26T21:15:25.8004068",
                "UpdateTime": "2012-07-26T21:16:06.6100785",
                "IsEnabled": "1",
                "IsDeleted": "0"
            }
        }
    ]
}

JSON 中的属性相当于 mysql 中的列。

4

1 回答 1

1

您可以用您选择的语言编写代码(您只需要一个 JSON 读取工具和一个 MySQL 客户端,但这些天都可以在所有语言中使用),或者您可以使用 ETL 工具。

使用 ETL 的优势

对源或目标格式的更改(例如,您突然需要从 CSV 文件或 XML 文件中读取这些数据)或内容(添加、消失或重命名字段)通常可以通过重新配置工具来解决。

使用 ETL 的缺点

这是您必须管理的又一个(相当繁重的)基础架构,有些人会争辩说,使用 ETL 工具来完成这样的任务就像用大锤杀死苍蝇一样。

然而,根据您对灵活性的要求,ETL 可能是最好/最简单的解决方案。

于 2013-09-26T12:23:15.153 回答