我将 NSDictionary 发布到服务器并像这样获取 NSLog:
{"User":"abc@gmail.com","cartItems":[{"productName":"Apple 5s","Qty":1,"price":"1000"}],"userDiscounts":["0001"]}
但问题是当我在服务器端检查这些数据时:
{ '{"User":"abc@gmail.com","cartItems":': { '{"productName":"Apple 4s","Qty":1,"price":"1000"}],"userDiscounts"': { '"0001"]': '' } } }
我的意思是,进入 '{ and }'
服务器端。这两个 json 字典有什么问题。
这是我的方法:
// Convert object to data, cartDictionary holding data.
NSData* postData = [NSJSONSerialization dataWithJSONObject:cartDictionary options:kNilOptions error:&error];
NSMutableURLRequest *request= [[NSMutableURLRequest alloc] init];
[request setURL:[NSURL URLWithString:combineProductUrl]];
[request setHTTPMethod:@"POST"];
[request setHTTPBody:postData];
// print json:
NSLog(@"JSON summary: %@", [[NSString alloc] initWithData:postData
encoding:NSUTF8StringEncoding]);