我有,我想將其轉換爲JSON字符串喜歡的NSDictionary值:無法轉換NSDictionary中值JSON
{
body = "10-feb";
comments = (
);
complete = 1;
"created_at" = "2014-02-09T15:56:01Z";
"due_at" = "2014-01-10 20:00:00 +0000";
"due_on" = "2014-10-02";
id = 439824;
"notification_sent" = 0;
"notify_user" = 0;
"organization_id" = 972;
participants = (
);
reminders = (
);
starred = 0;
"updated_at" = "2014-02-09T15:56:01Z";
"user_id" = 11129;
}
,我將其轉換爲JSON的方法是:
- (NSString*) jsonStringWithPrettyPrint:(BOOL) prettyPrint str:(NSDictionary *)str {
NSError *error = nil;
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:str
options:(NSJSONWritingOptions) (prettyPrint ? NSJSONWritingPrettyPrinted : 0)
error:&error];
if (! jsonData) {
NSLog(@"jsonStringWithPrettyPrint: error: %@", error.localizedDescription);
return @"{}";
} else {
return [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
}
}
我不知道爲什麼它總是無法轉換。?
你得到了什麼錯誤? – Sulthan
'due_at'是一個'NSDate'嗎? – Wain
是的,它是一個NSDate ..我已經增加了非凡的突破點以及..它停止,但我試着按繼續得到在控制檯中的堆棧跟蹤,但沒有記錄和錯誤仍然無。 –