-1

データをマップする方法JsonConvertNewtonsoft.Json を使用しており、ループ foreach データを使用して jsonString を jsonObject に変換しています。jsonObject all からグループ化したい以下の結果のようなデータを取得したいと考えています。助けてくれてありがとう。

私のパラメータ:

public class FundInPortRes
{
    public string fcode { get; set; }
    public string abbreviation { get; set; }
    public string chnfname { get; set; }
    public string AMC { get; set; }
    public string chnmain_scope { get; set; }
    public string risklevel { get; set; }
    public List<FundInPortNAVRes> NAV { get; set; }
}

public class FundInPortNAVRes
{
    public string fcode { get; set; }
    public string navdate { get; set; }
    public string nav { get; set; }
    public double navDiff { get; set; }
}

私のコード:

Array Data F.NAV = [{"fcode":"004123"}, {"nav":"12.83210"}, {"navdate":"20190305"}, {"navDiff":"-0.0351"}]

    [HttpPost]
    public List<Models.FundInPortRes> GetFund2InPort(Models.FundInPortReq model)
    {
        DataAccess.DashDAL dal = new DataAccess.DashDAL();
        List<Models.FundAllRes> models = dal.GetFund2InPort(model);
        List<Models.FundInPortRes> result = new List<Models.FundInPortRes>();

        if (models.Count > 0)
        {
            foreach (var F in models)
            {
                 Models.FundInPortRes resData = new Models.FundInPortRes();
                 resData.fcode = F.fcode;
                 resData.abbreviation = F.abbreviation;
                 resData.chnfname = F.chnfname;
                 resData.AMC = F.AMC;
                 resData.chnmain_scope = F.chnmain_scope;
                 resData.risklevel = F.risklevel;
                 resData.NAV = JsonConvert.DeserializeObject<List<Models.FundInPortNAVRes>>(F.NAV);
                 result.Add(resData);
           }
       }

       return result;
    }

私の結果:

[{
    "fcode": "004009",
    "abbreviation": "FLEX-RMF",
    "AMC": "ONEONLINE",
    "chnmain_scope": "Fund All",
    "risklevel": "5",
    "NAV": [{
            "fcode": "004009",
            "navdate": null,
            "nav": null,
            "navDiff": 0.0
        },
        {
            "fcode": null,
            "navdate": null,
            "nav": "27.14270",
            "navDiff": 0.0
        },
        {
            "fcode": null,
            "navdate": "20190306",
            "nav": null,
            "navDiff": 0.0
        },
        {
            "fcode": null,
            "navdate": null,
            "nav": null,
            "navDiff": -0.1715
        }
    ]
}]

私が望む結果:

[{
    "fcode": "004009",
    "abbreviation": "FLEX-RMF",
    "AMC": "ONEONLINE",
    "chnmain_scope": "Fund All",
    "risklevel": "5",
    "NAV": [{
            "fcode": "004009",
            "navdate": "20190306",
            "nav": "27.14270",
            "navDiff": -0.1715
        }
    ]
}]
4

1 に答える 1