嘿,我需要使用NSDictionary对象数组发出HTTP POST请求.
但是,当我这样做时,我注意到在服务器端,NSDictionary对象没有被反序列化为哈希.它被反序列化为一个字符串 - 这不是我想要的.
这是我从客户端(IPhone)端发送参数的方式:
ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url];
for (ABContact *c in contactsWithEmailsOrPhones){
NSString *phoneNumber = [[ABContactsHelper class] contactPhoneNumber:c];
NSString *email = [[c emailArray] objectAtIndex:0];
NSLog(@"looping: %@, %@", phoneNumber, email);
NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys:
phoneNumber,
@"phone",
email,
@"email",
[c firstname],
@"firstname",
[c lastname],
@"lastname", nil];
[request addPostValue:dict forKey:@"contacts[]"];
}
[request setDelegate:self];
[request startAsynchronous];
Run Code Online (Sandbox Code Playgroud)
这是它在服务器(rails)端反序列化时的样子:
Started POST "/app/find_friends" for 67.164.97.48 at Thu Sep 23 14:40:37 -0700 2010
Processing by app#find_friends as HTML
Parameters: {"contacts"=>["{\n email = \"xx\";\n …Run Code Online (Sandbox Code Playgroud) 我看到我的应用程序在与分配工具一起使用时崩溃了.查看设备日志时,我可以看出它是"低内存"崩溃.除了我的应用程序使用的其他应用程序进程外,我的应用程序进程被放弃了.以下是设备日志的外观:
MyAPP <09da004ccd82e7a2c54e0ea6ab4eab24> 1990 (jettisoned) (active)
MobilePhone <6d3241e15be58311a76700272febc6d4> 635 (jettisoned)
accessoryd <6a25188f645a24b167cda5e0a86d486a> 121 (jettisoned)
Run Code Online (Sandbox Code Playgroud)
当应用程序在没有仪器的情况下运行时,我不会遇到任何崩溃,并且用户认为该应用程序具有高性能.我一直专注于解决这个问题几天(几乎所有的代码都被评论以找到问题).
我的问题是 - 当与乐器一起使用时,应用程序崩溃会给最终用户带来问题吗?或者这只会在调试内存问题时引起问题?
注1:在使用仪器时,我没有与应用程序进行交互.它加载一个视图控制器,进行异步服务调用,返回结果,然后填充到两个tableview中.由于仍然需要对象,因此解除分配的次数不多.
注意2:这是应用程序崩溃时Allocations Instruments的LIVE对象列表片段(按照desc顺序按大小排序).正如你所看到的,MYAPP并不是主要的罪犯(貌似)
Size(bytes) Responsible Library Responsible Caller
131072 UIKit -[UIView(Internal) _subclassImplementsDrawRect]
45056 CoreGraphics zone_malloc
16384 libCGFreetype.A.dylib ft_allocate
11264 Foundation NSPopAutoreleasePool
8192 libCGFreetype.A.dylib ft_allocate
8192 Foundation NSLogv
7680 libCGFreetype.A.dylib ft_allocate
7680 libCGFreetype.A.dylib ft_allocate
7680 CoreGraphics argb32_mark_constmask
5120 CoreGraphics CGDataProviderCreateWithCopyOfData
4608 libCGFreetype.A.dylib ft_allocate
4608 libCGFreetype.A.dylib ft_allocate
4608 libCGFreetype.A.dylib ft_allocate
4096 libSystem.B.dylib __stack_chk_fail
4096 QuartzCore CA::Transaction::create()
4096 Foundation NSPushAutoreleasePool
4096 MYAPP -[CJSONScanner scanNotQuoteCharactersIntoString:]
Run Code Online (Sandbox Code Playgroud)
谢谢
这是我收到的错误消息:
ContactsWithPN - start loop
Program received signal: “0”.
Data Formatters temporarily unavailable, will re-try after a 'continue'. (Unknown error loading shared library "/Developer/usr/lib/libXcodeDebuggerSupport.dylib")
Run Code Online (Sandbox Code Playgroud)
以下是导致此问题的代码:
+(NSArray *) contactsWithPhoneNumbers{
NSArray *contacts = [ABContactsHelper contacts];
NSMutableArray *rv = [[NSMutableArray alloc] init];
NSLog(@"ContactsWithPN - start loop");
for (int i = 0; i< [contacts count] ; i++) {
ABContact * c = (ABContact*)[contacts objectAtIndex:i];
ABContact * fullContact = [ABContact contactWithRecordID:[c recordID]];
if ([[fullContact phoneArray] count] > 0) {
[rv addObject:fullContact];
}
}
NSLog(@"ContactsWithPN - …Run Code Online (Sandbox Code Playgroud) 这是我非常基本的GET功能
app.get('/', function(request, response) {
response.contentType('application/json');
var lid = request.param("lid");
client.llen(lid, function(reply, len){
client.lrange(lid, 0, len-1, function(reply, messages){
console.log(messages);
response.send(messages);
})
});
});
Run Code Online (Sandbox Code Playgroud)
出于某种原因,控制台输出和我得到的响应看起来像
[ <Buffer 5b 7b 22 6c 61 77 79 65 72 5f ... 61 64 61 74 61 22 3a 22 36 22 7d 5d> ]
Run Code Online (Sandbox Code Playgroud)
我将这些存储为JSON字符串:
client.lpush(lid, JSON.stringify(to_store))
Run Code Online (Sandbox Code Playgroud)
为什么我的响应不是JSON字符串?
谢谢.