You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用ChoETL转换动态JSON到CSV:外层嵌套数组处理问题及解决

问题:嵌套JSON转CSV时ChoETL处理外部数组异常

原JSON数据

{
  "Member": [
    {
      "Date": "2024-04-18T12:30:00Z",
      "Information": {
        "Name": "Joe",
        "Reference": "AAA0866",
        "Email": "test@test.com",
        "Telephone": "01234 555555",
        "Address": {
          "Line1": "1 Street",
          "Line2": "City",
          "Zipcode": "012345"
        },
        "Employment": [
          {
            "EmployerName": "AAA Ltd",
            "StartDate": "1980-04-01",
            "EndDate": "1990-11-01"
          },
          {
            "EmployerName": "ABC Ltd",
            "StartDate": "1990-12-01",
            "EndDate": "1995-10-01"
          }
        ]
      },
      "PaymentInformation": [
        {
          "Type": "A",
          "Amount": 2000,
          "Increased": true
        },
        {
          "Type": "B",
          "Amount": 1000,
          "Increased": false
        }
      ],
      "ExtraInfo": [
        {
          "Info": "ABC",
          "Comments": [
            "A", "B", "C"
          ]
        },
        {
          "Info": "EFG",
          "Comments": [
            "E", "F", "G"
          ]
        }
      ]
    },
    {
      "Date": "2024-04-18T12:30:00Z",
      "Information": {
        "Name": "Jane",
        "Reference": "CZE0866",
        "Email": "test1@test.com",
        "Telephone": "01234 12345",
        "Address": {
          "Line1": "12 Street",
          "Line2": "City",
          "Zipcode": "0123450"
        },
        "Employment": [
          {
            "EmployerName": "CZE Ltd",
            "StartDate": "1960-04-01",
            "EndDate": "1980-11-01"
          }
        ]
      },
      "PaymentInformation": [
        {
          "Type": "A",
          "Amount": 3000,
          "Increased": true
        }
      ],
      "ExtraInfo": [
        {
          "Info": "XYZ",
          "Comments": [
            "X", "Y", "Z"
          ]
        }
      ]
    },
    {
      "Date": "2024-04-18T12:30:00Z",
      "Information": {
        "Name": "John",
        "Reference": "ZYZ0866",
        "Email": "test2@test.com",
        "Telephone": "01234 121121",
        "Address": {
          "Line1": "123 Street",
          "Line2": "City",
          "Zipcode": "01234567"
        },
        "Employment": [
          {
            "EmployerName": "ABC Ltd",
            "StartDate": "2000-04-01",
            "EndDate": "2001-11-01"
          }
        ]
      },
      "PaymentInformation": [
        {
          "Unavailable": "TBC"
        }
      ],
      "ExtraInfo": [
        {
          "Unavailable": "TBC"
        }
      ]
    }
  ]
}

问题描述

基于.NET 8和ChoETL包实现上述JSON转CSV,已完成所有POCO类的映射与装饰,以及转换类的编写。其中Employment数组可以正常处理,但PaymentInformation或ExtraInfo数组无法正常工作,要么输出为空,要么出现空引用异常。

若将PaymentInformation或ExtraInfo数组放到Information内部、与Employment同级,该解决方案可以正常工作,但这两个数组实际位于Information外部,即使已相应调整POCO类映射,仍无法解决问题。

期望的CSV格式

Date,Name,Reference,Email,Telephone,AddressLine1,AddressLine2,Zipcode,EmployerName,EmplymentStartDate,EmplymentStartEndDate,EmployerName1,EmplymentStartDate1,EmplymentStartEndDate1,PaymentType,PaymentAmout,PaymentIncreased,PaymentType1,PaymentAmout1,PaymentIncreased1,ExtraInfo,Comments,ExtraInfo1,Comments1
2024-04-18 12:30:00,Joe,AAA0866,test@test.com,01234 555555,1 Street,City,012345,AAA Ltd,1980-04-01,1990-11-01,ABC Ltd,1990-12-01,1996-10-01,A,2000,true,B,1000,false,ABC,A+B+C,EFG,E+F+G
2024-04-18 12:30:00,Jane,CZE0866,test1@test.com,01234 12345,12 Street,City,0123450,CZE Ltd,1960-04-01,1980-11-01,,,,A,3000,true,,,,XYZ,X+Y+Z,,
2024-04-18 12:30:00,John,ZYZ0866,test2@test.com,01234 121121,123 Street,City,01234567,ABC Ltd,2000-04-01,2001-11-01,,,,,,,,,,,,,

更新:
通过使用Newtonsoft.Json.Linq中的JObject和JArray调整数组位置,已解决该问题。


内容的提问来源于stack exchange,提问作者Charline

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.25 14:05:15