【发布时间】:2018-06-21 06:45:39
【问题描述】:
我有两个列表,我正在尝试根据 Group => ID 和 Artist => GroupID 加入。
当我显示组时,我想从艺术家列表中显示组中的所有成员。
var groupID = from Group in allGroups join Artist in allArtists on Group.Id equals Artist.GroupId into Members where Group.Id == id select new { Group = Group.GroupName, Members }; return Json(groupID);
当 JSON 数据在浏览器中呈现时,我从每个艺术家那里获取所有数据,我只想显示名称。见下文:
[{"group":"G-Unit","members":[{"artistName":"Lloyd Banks","realName":"Christopher Lloyd","age":34,"hometown":"纽约市","groupId":2,"group":null},{"artistName":"The Game","realName":"Jayceon Taylor","age":37,"hometown":"Compton" ,"groupId":2,"group":null},{"artistName":"50 Cent","realName":"Curtis Jackson","age":41,"hometown":"New York City"," groupId":2,"group":null}]}]
提前感谢您的帮助!
【问题讨论】:
-
注意:您的源不是 JSON,它是(加入的).NET 枚举或集合或数组。只有您的输出是 JSON。
-
您说的完全正确,感谢您的澄清。