//dic 轉json 若是用系統自帶的會出現空格。 + (NSString *)returnJSONStringWithDictionary:(NSDictionary *)dictionary{ //系統自帶 // NSError * error; // NSData * jsonData = [NSJSONSerialization dataWithJSONObject:dictionary options:kNilOptions error:&error]; // NSString * jsonStr = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding]; //自定義 NSString *jsonStr = @"{"; NSArray * keys = [dictionary allKeys]; for (NSString * key in keys) { jsonStr = [NSString stringWithFormat:@"%@\"%@\":\"%@\",",jsonStr,key,[dictionary objectForKey:key]]; } jsonStr = [NSString stringWithFormat:@"%@%@",[jsonStr substringWithRange:NSMakeRange(0, jsonStr.length-1)],@"}"]; return jsonStr; }