- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在发出异步请求,并且在 [responseData setLength:0];
代码是:
- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response {
[responseData setLength:0];
}
-(void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data {
[responseData appendData:data];
}
-(void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error {
NSLog(@"Connection failed: %@", [error description]);
}
-(void)connectionDidFinishLoading:(NSURLConnection *)connection {
NSString *responseString = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];
[responseData release];
luckyNumbers1 = [responseString JSONValue];
NSUserDefaults *information = [NSUserDefaults standardUserDefaults];
/*NSArray *luckyNumbers = [json objectWithString:responseString error:&error];*/
NSLog(@"luckyNumbers1: %@", luckyNumbers1);
NSLog(@"user Info array is: %@", luckyNumbers1);
// [information setObject:[NSString stringWithFormat:@"%@", (NSString *)[luckyNumbers1 objectForKey:@"session"]] forKey:@"sessionID"];
NSDictionary *array = (NSDictionary *)[luckyNumbers1 objectForKey:@"data"];
NSEnumerator *inner = [luckyNumbers1 objectEnumerator];
id value;
while((value = [inner nextObject])) {
NSLog(@"user Info array is: %@", value);
if ( [value isKindOfClass:[NSDictionary class]] ) {
[information setObject:[value objectForKey:@"id"] forKey:@"userID"];
NSLog(@"uid is: %@", [value objectForKey:@"id"]);
[information setObject:[NSString stringWithFormat:@"%@", (NSString *)[value objectForKey:@"points_all"]] forKey:@"pointString"];
[information setObject:[NSString stringWithFormat:@"%@", (NSString *)[[[value objectForKey:@"leaderboards"] objectForKey:@"all"] objectForKey:@"position"]] forKey:@"rankString"];
if ((NSNull *)[value objectForKey:@"display_name"] == [NSNull null]) {
[information setObject:@"No Display Name" forKey:@"displayNameString"];
} else {
[information setObject:[NSString stringWithFormat:@"%@", (NSString *)[value objectForKey:@"display_name"]] forKey:@"displayNameString"];
}
if ((NSNull *)[value objectForKey:@"level"] == [NSNull null]) {} else {
[information setObject:[NSString stringWithFormat:@"%@", (NSString *)[[[value objectForKey:@"level"] objectForKey:@"definition"] objectForKey:@"name"]] forKey:@"levelString"];
}
pointsTV = [[UILabel alloc] initWithFrame:CGRectMake(222, 294, 441, 22)];
pointsTV.text = [NSString stringWithFormat:@"Points: %@", [information stringForKey:@"pointString"]];
pointsTV.backgroundColor = [UIColor clearColor];
pointsTV.textColor = [UIColor whiteColor];
[TVWindow addSubview:pointsTV];
rankLabelTV = [[UILabel alloc] initWithFrame:CGRectMake(222, 269, 441, 22)];
rankLabelTV.backgroundColor = [UIColor clearColor];
rankLabelTV.textColor = [UIColor whiteColor];
rankLabelTV.text = [NSString stringWithFormat:@"Rank: %@", (NSString *)[[[array objectForKey:@"leaderboards"] objectForKey:@"all"] objectForKey:@"position"]];
[TVWindow addSubview:rankLabelTV];
levelNameLabelTV = [[UILabel alloc] initWithFrame:CGRectMake(222, 244, 441, 22)];
levelNameLabelTV.backgroundColor = [UIColor clearColor];
levelNameLabelTV.textColor = [UIColor whiteColor];
if ((NSNull *)[value objectForKey:@"level"] == [NSNull null]) {
levelNameLabelTV.text = @"No Level";
} else {
levelNameLabelTV.text = [NSString stringWithFormat:@"Level: %@", (NSString *)[[[array objectForKey:@"level"] objectForKey:@"definition"] objectForKey:@"name"]];
}
[TVWindow addSubview:levelNameLabelTV];
pointLabel.text = [information stringForKey:@"pointString"];
pointLabel.textAlignment = UITextAlignmentLeft;
displayNameLabelTV.text = [information stringForKey:@"displayNameString"];
displayNameLabel. text = [information stringForKey:@"displayNameString"];
rankLabel.text = [information stringForKey:@"rankString"];
levelLabel.text = [information stringForKey:@"levelString"];
NSURL *url1 = [NSURL URLWithString: [NSString stringWithFormat:@"%@", (NSString *)[array objectForKey:@"picture_url"]]];
NSData *urlData1 = [NSData dataWithContentsOfURL:url1];
UIImage *image1 = [UIImage imageWithData:urlData1];
profilePicture.image = image1;
profilePictureTV.image = image1;
[information setObject:[NSString stringWithFormat:@"%@", (NSString *)[luckyNumbers1 objectForKey:@"session"]] forKey:@"sessionID"];
}}
NSURLRequest *request2;
request2 = [NSURLRequest requestWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://%@/api/widgets/%@/%@/players/%@/rewards.json", [information stringForKey:@"host"], [information objectForKey:@"apiKey"], [information objectForKey:@"URL"], [information objectForKey:@"userID"]]]];
NSLog(@"Badges Request is: %@", request2);
NSURLConnection *connection2;
connection2 = [[NSURLConnection alloc] initWithRequest:request2 delegate:self startImmediately:YES];
NSURLResponse *resp3;
NSData *cData2 = [NSURLConnection sendSynchronousRequest:request2 returningResponse:&resp3 error:nil];
NSString *cDataString2 = [[NSString alloc] initWithData:cData2 encoding:NSUTF8StringEncoding];
[self getUsersBadges: cDataString2];
[[NSURLConnection alloc] initWithRequest:request2 delegate:self];
// pass cDataString into the JSON parser and update points
[connection release];
}
最佳答案
如果没有看到 reponseData
的初始化,很难确定,但我猜你要么将其声明为 [NSMutableData data]
(这将得到autoreleased) 或 release
/autorelease
在到达 -connection:didReceiveResponse:
之前对其进行处理。解决方案是确保它不会提前释放,方法是对其调用 retain
或使用 [[NSMutableData alloc] init]
对其进行初始化。在任何一种情况下,您都需要在完成后释放它,尽管看起来您已经在 -connectionDidFinishLoading:
中执行了该操作,因此无需进行任何更改。
关于iphone - 崩溃 [responseData setLength :0];,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6933001/
我想编写一个附加到整数数组的过程,但 Delphi IDE 给我编译时错误“不兼容类型”。这是我的代码: procedure appendToIntegerArray(var intArr : arr
在 Delphi 中,可以创建该类型的数组 var Arr: array[2..N] of MyType; 这是一个由 N - 1 元素组成的数组,索引从 2 到 N。 如果我们声明一个动态数组
我正在尝试使用以下函数来设置动态数组的长度,该数组是 var 参数。当我尝试编译代码时只有一个错误: [dcc64 错误] lolcode.dpr(138): E2008 不兼容类型 function
当然,即使我也能做到...... var testarray : array of string; setlength(testarray, 5); 但是如果我想变得聪明并有一个过程来通过引用传递
这个问题可能会也可能不会解决我的问题 - 但我希望了解 Delphi/Windows 如何以可能导致此问题的方式运行。 我有一个使用 3rd 方组件来加载 Outlook .msg 文件的应用程序。
在某些情况下,我需要设置动态数组的大小,然后用零填充它。 类似于: procedure SetLengthAndZero(VAR X; NewSize: Integer); begin SetL
今天我偶然发现了一个导致我的数组损坏的问题。这是一个可重现的测试用例: unit Unit40; interface type TVertex = record X, Y: Double;
我一直在阅读 RandomAccessFile 并了解可以通过 setLength 将文件末尾截断为比文件短的长度。我试图将文件的“结尾”复制到新文件并截断开头。 例如:我想删除文件的前 1300
在 stringbuilder 中修剪到一定长度。 我应该使用什么? StringBuilder sb = new StringBuilder("203253/62331066
我有这个代码: [[self.receivedData objectForKey:[NSNumber numberWithInt:connection.tag]] setLength:0]; 重复三次
这个问题已经有答案了: Clear contents of a file in Java using RandomAccessFile (2 个回答) 已关闭 9 年前。 我正在尝试清除用 java
我正在发出异步请求,并且在 [responseData setLength:0]; 上收到 EXC_BAD_ACCESS 代码是: - (void)connection:(NSURLConnectio
我有以下代码来生成字符串的所有可能的子字符串: import java.util.*; public class PlayString { public static void main(St
我需要创建一个包含记录对象数组的类,但尝试使用 SetLength 会引发访问冲突错误。 考虑以下带有水果的树对象示例。 type TFruit = record color: string;
尝试创建请求与 URL 的连接。 NSMutableData 实例(responseData)也会随之被调用。当连接开始接收响应时,将在 NSMutableData 实例上调用 setLength:N
代码说明 procedure TForm1.FormCreate(Sender: TObject); var Str: string; PStr: PChar; begin Str :=
我正在尝试调整作为参数传递的某个类的数组的大小,例如 procedure Resize(MyArray: Array of TObject); begin SetLength(MyArray, 1
我正在比较这两种初始化动态数组的方法之间的性能: Arr := TArray.Create(1, 2, 3, 4, 5); 和 SetLength(Arr, 5); Arr[0] := 1; Arr[
这是代码: package vu.co.kaiyin; import java.io.FileOutputStream; import java.io.RandomAccessFile; import
我有一个动态数组myArr。当我们使用 SetLength 时,myArr 的内存中存储了什么?是“00”吗?还是未定义?在本例中, SetLength 为 myArr 分配 16 字节内存。 myA
我是一名优秀的程序员,十分优秀!