【发布时间】:2015-07-24 07:44:42
【问题描述】:
我想更改以下 JSON。 我的要求是我想在循环中将 ("answer": "offlinetesing") 替换为 ("answer": "test12333") 。假设如果它在索引 0 中,我只想替换索引 0 的答案。
我怎样才能做到这一点?
我正在使用此代码
NSData *data = [NSData dataWithContentsOfFile:documentFile1];
NSMutableDictionary *jsonObject1 = [NSKeyedUnarchiver unarchiveObjectWithData:data];
NSLog(@"jsonObject1 is %@",jsonObject1);
NSMutableArray *responsedictonary=[jsonObject1 objectForKey:@"questions"];
JSON:
{
"currentquestion": "Define6",
"phasecompletion": "80",
"questions": [
{
"answer": "offlinetesing",
"dmaicQuestion_ID": "Define1",
"projectPhase": "Define"
},
{
"answer": "testing",
"dmaicQuestion_ID": "Define2",
"projectPhase": "Define"
}
],
"questionsAnswered": 8
}
【问题讨论】:
-
这意味着你只需要从
questions标签的第一个对象中替换“answer”:“offlinetesing”?? -
制作一个可变的 dict 副本并将“answer”设置为“whatever you want to set”
标签: ios objective-c json nsarray nsdictionary