真的很难弄清楚这一点。只是试图从php中获取数据
curRow = [[NSMutableArray alloc]init];
[curRow addObject:[JSON valueForKeyPath:@"question"]];
[curRow addObject:[JSON valueForKeyPath:@"answers"]];
[curRow addObject:[JSON valueForKeyPath:@"correct_answer"]];
[gameQuestions addObject:curRow];
在另一种方法中,我正在这样做
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);
但是当我查看调试日志时,我的问题和答案是同一个对象?
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"
)
我肯定错过了什么
在 php 中它只是一个简单的 while 循环
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);
有任何想法吗?