json - 当对象具有相同的值时,如何在我的 tableView 中显示 JSON 数据?
问题描述
我正在尝试根据具有相同值的对象在我的 tableview 单元格中显示 JSON 数据。
现在,我可以将所有 JSON 数据显示到我的单元格行中,但我无法排除不具有相同对象值的数据。
我正在使用此设置来获取数据:
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
// Retrieve cell
let cellIdentifier: String = "takesTableViewCell"
let myCell: TakesTableViewCell = tableView.dequeueReusableCell(withIdentifier: cellIdentifier)! as! TakesTableViewCell
// Get the location to be shown
let item: LocationModel = feedItems[indexPath.row] as! LocationModel
// Get references to labels of cell
myCell.mainNameLabel.text = item.title
myCell.mainTakeLabel.text = item.take
return myCell
}
这是我拥有的示例 JSON 数据
[
{
"id":"1",
"title":"Great Title 1",
"take":"Testing !!!",
"movieid":"299534"
},
{
"id":"2",
"title":"Great Title 2",
"take":"Testing 1,2,3",
"movieid":"299666"
},
{
"id":"3",
"title":"Great Title 3",
"take":"Testing 1,2,3",
"movieid":"299534"
}
]
我只想显示具有相同“movieid”的结果,如下所示:
标题:伟大的标题 1
采取:测试!
Title: Great Title 3
Take:测试 1,2,3
解决方案
在后端,您只想返回 movieid 数量计数 > 1 的记录
SELECT *
FROM movie_table
GROUP BY movie_id
HAVING COUNT(movie_id) > 1;
推荐阅读
- angular - 使用 FormControlName 的 Mat-Autocomplete 不显示我想要的值
- java - Java中的内部类与公共内部类
- java - 将 JSON 数组数组转换为特定类的 Java 列表
- spring-boot - cipher suites spring 高加密(aes+camellia no aead)
- excel - VBA:发送多封电子邮件,正文和表格中的.jpg作为附件
- mysql - MySQL函数计算CRC16
- sql - 如何在蜂巢中进行字数统计
- c++ - 如何使用自定义上下文菜单编辑 QListwidgetItem?
- pandas - 如何在 Python 中使用数据帧中的所有值绘制 3d 曲面
- azure-logic-apps - Microsoft 的逻辑应用程序在接受自定义连接器数据时出错