I'm having issues seperating how to handle two JSOn responses. IF there is only one element returned, it gives a different response than two:
Here is one result:
{
"voteMap": {
"SID": "2727",
"CNT": "1",
"VTD": "N"
}
}
And two:
{
"voteMap": [
{
"SID": "2814",
"CNT": "1",
"VTD": "N"
},
{
"SID": "2815",
"CNT": "1",
"VTD": "N"
}
]
}
I go from having one array to having an array of dictionaries. Here is how I am handling it:
responseArr = jsonArray[@"voteMap"];
if([jsonArray count] == 1){
Song* song = [self findSong:[responseArr valueForKey:@"SID"]];
song.votes =[responseArr valueForKey:@"CNT"];
song.status = [responseArr valueForKey:@"VTD"];
}
else{
for (NSDictionary *dict in responseArr) {
Song *song = [self findSong:[dict valueForKey:@"SID"]];
song.votes =[dict valueForKey:@"CNT"];
song.status = [dict valueForKey:@"VTD"];
}
}
Sorry about the bad formatting. What is happening is the [jsonArray count] == 1
is always happening...presumable because it always returns voteMap