Ich bin ein JSON-POST-Anforderung von Objective C Erstellung der JSON-Bibliothek wie folgt:iphone Json POST-Anforderung an Django-Server erstellt QueryDict innerhalb 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];
Als ich diese Anfrage in meinem Django lesen Sie den Debugger sehen zeigt nahm es die gesamte Zeichenfolge JSON und es der erste Schlüssel des POST QueryDict gemacht:
POST QueryDict: QueryDict: {u'{"foo":"12","bar":"*"}': [u'']}> Error Could not resolve variable
ich den ersten Schlüssel lesen und Analysepunkte, dann als ein Hack mit JSON. Aber warum wird die JSON-Zeichenfolge nicht korrekt gesendet?