Reputation: 87
I am trying to parse the following JSON but i am getting the following error.
"Error Could not find an object mapping for keyPath: '' "
As far as i understand it is because I havent provided a SetMapping: forKeyPath: but i cannot set this because the key will change as you can see in the JSON e.g. BBC ONE, BBC TWO and so on. I do not need to save the service name as i plan on cross referencing the SID with another json file that contains these details stored in core data to provide this. (if its possible). Is there a way around this error?
Here is my JSON (cut down version)
{
"BBC ONE": [
{
"Name": "Programme 1",
"Description": "A desc of a programme",
"ONID": 1,
"TSID": 2,
"SID": 3,
"CRID": "crid_address"
},
{
"Name": "Programme 2",
"Description": " Another desc",
"ONID": 9,
"TSID": 99,
"SID": 999,
"CRID": "crid_2"
}
],
"BBC TWO": [
{
"Name": "bbc_programme",
"Description": "programme 2",
"Event ID": 4,
"ONID": 9,
"TSID": 4,
"SID": 4,
"CRID": "crid"
}
]
}
and more.
Here is my code:
RKManagedObjectMapping *epgMapping = [RKManagedObjectMapping mappingForClass:[Epg class] inManagedObjectStore:objectManager.objectStore];
[epgMapping mapKeyPathsToAttributes:@"Name",@"name",
@"Description", @"desc",
@"Event ID", @"event_id",
@"ONID", @"onid",
@"TSID", @"tsid",
@"SID", @"sid",
@"CRID", @"crid",nil];
epgMapping.primaryKeyAttribute = @"crid";
Any Help would be appreciated as i have read various documents and looked at other peoples issue and cannot find a solution.
Thanks
Upvotes: 0
Views: 237
Reputation: 450
You're storing a value in the name portion of the json name-value pair. Suggest changing your json (if you can) to something like this:
"Name" : "BBC ONE",
"Programs" : [
{
"Name": "Programme 1",
"Description": "A desc of a programme",
"ONID": 1,
"TSID": 2,
"SID": 3,
"CRID": "crid_address"
},
{
"Name": "Programme 2",
"Description": " Another desc",
"ONID": 9,
"TSID": 99,
"SID": 999,
"CRID": "crid_2"
}
Upvotes: 1