【发布时间】:2015-08-02 15:44:47
【问题描述】:
我的代码从服务器接收 json 数据并呈现到 UItable 中。这是我从服务器获取的 josn 文件的格式:
[
{
"id": 4342,
"name": "Strawberries and Cream Cake",
"difficulty": 3,
"created_at": "2014-09-29T10:43:00.072Z",
"updated_at": "2014-11-26T11:53:58.451Z",
}
]
我需要访问“id”元素,我在 .
(void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
NSDictionary *tempDictionary=[recipes objectAtIndex:indexPath.row];
int recipesID= [tempDictionary objectForKey:@"id"];
这段代码给了我一个错误的数字,加上第二行因为“指向整数转换初始化的不兼容指针...... 我知道 id 是保留关键字,但我需要访问此元素。除了我没有实现服务器之外,我无法更改 id 元素名称。 您对如何访问它有什么建议吗?
【问题讨论】:
-
因为你得到的是一个NSNumber,而不是一个int,你必须在返回的NSNumber上调用
intValue
标签: ios json nsdictionary reserved-words