Afnetworking json into multidimensional matrix

Really trying my best to figure it out. Just trying to grab data from php

curRow = [[NSMutableArray alloc]init];
    [curRow addObject:[JSON valueForKeyPath:@"question"]];
    [curRow addObject:[JSON valueForKeyPath:@"answers"]];
    [curRow addObject:[JSON valueForKeyPath:@"correct_answer"]];
    [gameQuestions addObject:curRow];

      

in another method, i do this

int i = arc4random() % [gameQuestions count];
CCLOG(@"Random: %i", i);

currentQuestion = [[gameQuestions objectAtIndex:i]objectAtIndex:0];
currentAnswer = [[gameQuestions objectAtIndex:i]objectAtIndex:1];
currentCorrectAnswer = [[gameQuestions objectAtIndex:i]objectAtIndex:2];
CCLOG(@"question: %@", currentQuestion);
CCLOG(@"answer: %@", currentAnswer);

      

But when I look in the debug log, is my question and answer the same object?

2012-03-21 17:08:06.659 dunce[6849:707] Random: 0
2012-03-21 17:08:06.662 dunce[6849:707] question: (
    "Who was the 42nd president?",
    "What was the date that Microsoft released Windows 95?"
)
2012-03-21 17:08:06.666 dunce[6849:707] answer: (
    "Bill Clinton; Theodore Rosevelt; Barack Obama; Ronald Regan; ",
    "June 25th, 1994;September 3rd, 1992; August 24th, 1995; August 3rd, 1996"
)

      

I must be missing something

in php its just a simple loop

while($row = mysql_fetch_array($result))
{
    $resultArr[$co]['id'] = $row['id'];
    $resultArr[$co]['question'] = $row['question'];
    $resultArr[$co]['answers'] = $row['answers'];
    $resultArr[$co]['correct_answer'] = $row['correct_answer'];
    $co++;
}

echo json_encode($resultArr);

      

any ideas?

+3


source to share


1 answer


I recieved it.



    AFJSONRequestOperation *operation = [AFJSONRequestOperation JSONRequestOperationWithRequest:request success:^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON) {
    for(id entry in JSON)
    {
        NSMutableArray *curRow = [[NSMutableArray alloc]init];
        [curRow addObject:[entry valueForKeyPath:@"question"]];
        [curRow addObject:[entry valueForKeyPath:@"answers"]];
        [curRow addObject:[entry valueForKeyPath:@"correct_answer"]];
        [gameQuestions addObject:curRow];
        [curRow release];
        curRow = nil;            
    }

      

+5


source







All Articles