我正在IEnumerable<dynamic>使用 Rob Conery 的 Massive 框架从数据库中选择一个。该结构以平面格式 Poco C# 返回。我需要转换数据并将其输出到 Json 数组(格式显示在底部)。
我以为我可以使用 linq 进行转换(我的失败如下所示):
using System.Collections.Generic;
using System.Json;
using System.Linq;
using System.ServiceModel.Web;
....
    IEnumerable<dynamic> list = _repository.All("", "", 0).ToList();
    JsonArray returnValue = from item in list
                            select new JsonObject()
                                       {
                                               Name = item.Test,
                                               Data = new dyamic(){...}...
                                       };
这是我要生成的 Json:
[
    {
        "id": "1",
        "title": "Data Title",
        "data": [
            {
                "column1 name": "the value",
                "column2 name": "the value",
                "column3 name": "",
                "column4 name": "the value"
            }
        ]
    },
    {
        "id": "2",
        "title": "Data Title",
        "data": [
            {
                "column1 name": "the value",
                "column2 name": "the value",
                "column3 name": "the value",
                "column4 name": "the value"
            }
        ]
    }
]