ist mein Code unten angegeben, und ich bin die folgende Ausgabe bekommen, ist die Ausgabe in Ordnung, aber ich will nur die Ausgabe in einer durch Kommata getrennte Liste von Orten zu formatieren. Wie macht man das?Wie JSON Array von Objekten zu JSON Array von Strings zu konvertieren?
var eventDetails = (from e in db.tb_Event
select new
{
e.EventID,
e.tb_Customer.CustomerName,
e.StartDate,
e.EndDate,
loc = (from l in db.tb_EventLocation where
l.EventID == e.EventID
select new { l.tb_Location.LocationName })
.Distinct(),
e.Objective
});
Die Ausgabe lautet:
[
{
"EventID": 1,
"CustomerName": "qwe",
"StartDate": null,
"EndDate": null,
"loc": [
{
"LocationName": "asd"
},
{
"LocationName": "zxc"
}
],
"Objective": "Floor Walkthrough"
},
{
"EventID": 2,
"CustomerName": "rtg",
"StartDate": null,
"EndDate": null,
"loc": [
{
"LocationName": "asd"
}
],
"Objective": "RFP"
},
{
"EventID": 3,
"CustomerName": "zxc",
"StartDate": null,
"EndDate": null,
"loc": [],
"Objective": "RFI"
}
]
I loc als
[{"LocationName":"asd","zxc"}]
das heißt ein Komma Liste der Standorte getrennt kommen wollen. Wie macht man das?
So mögen Sie „Location“ sein, ein Array wie „loc“, rechts ? –
versuchen Sie mit etwas wie: eventDetails.Select (xx => xx.loc) .ToList() .. könnte in Ordnung sein? –
@ VítorMartins Ja – Prabhjot