【发布时间】:2015-01-01 16:40:17
【问题描述】:
这是我的 JSON 格式,它是从 Web 服务作为响应获得的,
"popups":
[
{
"sowhat":
{
"isAvailable": "TRUE",
"hasVideo": "FALSE",
"hasAudio": "TRUE",
"content": "<p><span><span><strong>SO WHAT?</strong></span></span></p><p><span><span> Belief shapes behaviour. But the question is, ‘How much?’ How much does the promised return of Jesus shape your behaviour from day to day? Do you find yourself thinking about it very much or maybe doubting it from time to time? Perhaps we can liken it to the final whistle or siren of a grand final. The whistle ends the match but in a much greater way the return of Jesus ends world history as we know it. His return ushers in the complete rule of God’s kingdom which began when Jesus came to earth. Does this reality shape what you do each day? Are you ready for his return?</span></span></p>"
}
},
{
"questions":
{
"isAvailable": "TRUE",
"hasVideo": "FALSE",
"hasAudio": "FALSE",
"content": "<p><span><span><strong>QUESTIONS </strong></span></span></p><ol><li><p><span><span>Read Luke 1:1-4. How is Acts both similar and different to Luke’s gospel?</span></span></p></li><li><p><span><span>What key Christian truths are mentioned in Acts 1:1-11?</span></span></p></li><li><p><span><span>How is the Holy Spirit related to the task assigned to the apostles (verse 8)?</span></span></p></li><li><p><span><span>If verse 8 hints at the broad outline of the book of Acts, where might the gospel arrive at by the conclusion of the book?</span></span></p></li><li><p><span><span>What does the choosing of Matthias demonstrate about the disciples’ attitude to the Scriptures?</span></span></p></li></ol>"
}
}
]
这是我用来在字典中解析的代码
NSDictionary *popupContents = [readingPlanContents valueForKeyPath:@"popups"];
//SoWhatPopup
NSDictionary *soWhatPopup = [popupContents valueForKey:@"sowhat"];
soWhatPopupAvlbl=[soWhatPopup valueForKey:@"isAvailable"];
NSString *soWhatVdeo=[soWhatPopup valueForKey:@"hasVideo"];
NSString *soWhatAdio=[soWhatPopup valueForKey:@"hasAudio"];
soWhatCntn=[soWhatPopup valueForKey:@"content"];
NSLog(@"soWhatVdeo:%@ ",soWhatVdeo);
NSLog(@"soWhatAdio:%@ ",soWhatAdio);
NSLog(@"soWhatCntn:%@ ",soWhatCntn);
NSLog(@"soWhatPopupAvlbl:%@ ",soWhatPopupAvlbl);
//QuestionPopup
NSDictionary *questPopup = [popupContents valueForKeyPath:@"questions"];
questPopupAvlbl=[questPopup valueForKey:@"isAvailable"];
NSString *questVdeo=[questPopup valueForKey:@"hasVideo"];
NSString *questAdio=[questPopup valueForKey:@"hasAudio"];
questCntn=[questPopup valueForKey:@"content"];
NSLog(@"Avaliable:%@ Content:%@",questPopupAvlbl,questCntn);
Log 值返回以下文本
soWhatVdeo:
(
FALSE,
"<null>",
"<null>",
"<null>",
"<null>"
)
2014-11-05 17:24:21.044 StandFirm[3655:100200] soWhatAdio:(
TRUE,
"<null>",
"<null>",
"<null>",
"<null>"
2014-11-05 17:24:21.044 StandFirm[3655:100200] soWhatCntn:(
"<p><span><span><strong>SO WHAT?</strong></span></span></p><p><span><span> Belief shapes behaviour. But the question is, ‘How much?’ How much does the promised return of Jesus shape your behaviour from day to day? Do you find yourself thinking about it very much or maybe doubting it from time to time? Perhaps we can liken it to the final whistle or siren of a grand final. The whistle ends the match but in a much greater way the return of Jesus ends world history as we know it. His return ushers in the complete rule of God’s kingdom which began when Jesus came to earth. Does this reality shape what you do each day? Are you ready for his return?</span></span></p>",
"<null>",
"<null>",
"<null>",
"<null>"
)
2014-11-05 17:24:21.045 StandFirm[3655:100200] soWhatPopupAvlbl:(
TRUE,
"<null>",
"<null>",
"<null>",
"<null>"
)
我不明白为什么它保持显示这么多空值而不是显示当前值。我的代码有什么问题?如何只获取值?请更正我的代码
【问题讨论】:
-
你解析 JSON 响应了吗?
-
让我们谈谈“弹出窗口”。它返回一个数组,而不是字典。将此值保存到
NSArray,然后再进一步。 -
@Kampai 绝对正确
标签: ios json dictionary nsdictionary