相关疑难解决方法(0)

对Django服务器的iphone Json POST请求在QueryDict中创建QueryDict

我正在使用JSON库从Objective C创建一个JSON POST请求,如下所示:

NSMutableURLRequest *request;
request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@/%@/", host, action]]];
[request setHTTPMethod:@"POST"];
[request setValue:@"application/json-rpc" forHTTPHeaderField:@"Content-Type"];
NSMutableDictionary *requestDictionary = [[NSMutableDictionary alloc] init];
[requestDictionary setObject:[NSString stringWithString:@"12"] forKey:@"foo"];
[requestDictionary setObject:[NSString stringWithString@"*"] forKey:@"bar"];

NSString *theBodyString = requestDictionary.JSONRepresentation;
NSData *theBodyData = [theBodyString dataUsingEncoding:NSUTF8StringEncoding];   
[request setHTTPBody:theBodyData];  
[[NSURLConnection alloc] initWithRequest:request delegate:self];

当我在Django视图中读取此请求时,调试器显示它占用了整个JSON字符串并使其成为POST QueryDict的第一个键:

POST    QueryDict: QueryDict: {u'{"foo":"12","bar":"*"}': [u'']}>   Error   Could not resolve variable

我可以读取第一个键,然后使用JSON作为黑客重新解析.但为什么JSON字符串没有正确发送?

iphone django json objective-c

6
推荐指数
1
解决办法
3050
查看次数

标签 统计

django ×1

iphone ×1

json ×1

objective-c ×1