JSON键与前导"@"的映射带有restkit [英] mapping of JSON keys with leading "@" with restkit
问题描述
我现在正在为某些项目使用Rest Kit 0.20.3,没有任何问题. 现在,我面临一个问题,即JSON密钥的前导"@"会导致Restkit在映射数据时崩溃.
I am working with rest kit 0.20.3 for some project now without issues. Right now I am facing the problem that the JSON keys have leading "@" which causes Restkit to crash while mapping the data.
JSON如下:
{
"city": {
"@name": "Charles Redirection City",
"@nameUrl": "Charles Redirection City",
"lat": "52.5238",
"long": "13.4119",
"zipCode": "666"
},
"categories": {
"@count": "20037",
"category": [
{
"@count": "2326",
"@hasChildren": "true",
"id": "15777",
"name": "Sticky-Categorie"
}
]
},
"additional": {
"dataKey": [
{
"@key": "log-start",
"$": "home"
}
]
}
}
使用
*** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<__NSCFDictionary 0x95b5360> valueForUndefinedKey:]: this class is not key value coding-compliant for the key hasChildren.'
,因为它尝试在字典上调用hasChildren.我的映射如下所示:
as it tries to call hasChildren on the dictionary. My mapping look like this:
[mapping addAttributeMappingsFromDictionary:@{
@"id" : @"categoryId",
@"name" : @"name",
@"@hasChildren" : @"doesHaveChildren",
@"@count" : @"numbersOfJobs",
@"trackingName" : @"trackingString"
}];
我已经尝试应用自己的映射,但不幸的是,该映射无法正常工作. RestKit不支持前导@吗?我已经使用NSJSONSerialization解析了JSON,该方法可以正常工作,但是我真的很喜欢RestKit的映射功能,并希望避免编写自己的映射:)
I already tried to apply my own mapping which unfortunately didn't work. Is a leading @ not supported in RestKit? I already parsed the JSON with NSJSONSerialization which worked fine but I really love the mapping feature of RestKit and would like to avoid writing my own mapping :)