我使用網絡服務來拉出JSON格式的一些信息時,我在做什麼錯。我可以在我的應用程序中查看它們。但是,當我嘗試將它們存儲在字典中時,我總是收到錯誤,說「valueId」值不符合。這是我任何想法設法從Web服務JSON存入的NSDictionary
NSMutableArray *results = [NSMutableArray array];
for (id courseDictionary in response) {
ListOfCourses *course = [[ListOfCourses alloc] initWithDictionary:courseDictionary];
[results addObject:course];
}
,在我ListOfCourses.m我有
- (id)initWithDictionary:(NSDictionary *)dictionary
{
self = [super init];
if (self) {
_courseId = [NSNumber numberWithInt:[[dictionary valueForKey:@"courseId"]
_room1 = [dictionary objectForKey:@"room1"];
_subjectCode = [dictionary objectForKey:@"subjectCode"];
}
return self;
}
JSON文件
{
"Template":{
"Room1":"Day 1 room name/number; string; required; 10 characters",
"SubjectId":"Subject identifier; number; required; Subject identifier must exist",
{
"Links":[
{
"Rel":"self",
"Href":"/api/courses/2"
},
{
"Rel":"collection",
"Href":"/api/courses/"
}
],
"Item":{
"Link":{
"Rel":"self",
"Href":"/api/courses/2"
},
"Id":1,
"SubjectCode":"D9920",
"Room1":"S2153"
}
更新:我返回對象的集合,當我做到這一點
_courses = (NSArray *)[response objectForKey:@"Collection"];
我是ab le查看對象。我試圖把它們各自獨立成字典現在
顯示你的json〜! – meda
你可以發佈錯誤日誌嗎? – Ilario
你在做什麼(非常)不清楚,但至少可以包括你在右邊界切斷的代碼嗎? –