Sto creando una richiesta JSON POST da Objective C utilizzando la libreria JSON in questo modo:iphone richiesta JSON POST al server Django crea QueryDict entro QueryDict
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 [email protected]"*"] forKey:@"bar"]; NSString *theBodyString = requestDictionary.JSONRepresentation; NSData *theBodyData = [theBodyString dataUsingEncoding:NSUTF8StringEncoding]; [request setHTTPBody:theBodyData]; [[NSURLConnection alloc] initWithRequest:request delegate:self];
Quando ho letto questa richiesta nel mio Django visualizzare il debugger mostra ha preso l'intera stringa JSON e ne ha fatto la prima chiave del POST QueryDict:
POST QueryDict: QueryDict: {u'{"foo":"12","bar":"*"}': [u'']}> Error Could not resolve variable
posso leggere il primo tasto e poi rianalizzare con JSON come un hack. Ma perché la stringa JSON non viene inviata correttamente?