我需要發送json數據到服務器。我能夠發送json對象到服務器。但我想發送多個json對象到像下面的服務器。發送多個json數據到服務器 - ios
Json1:
{
"Comments" : "test」,
"user_id" : 「test」,
"EdDate" : "08\/26\/2015 03:16:58 PM",
"StDate" : "08\/26\/2015 03:16:20 PM",
"latitude" : "",
"longitude" : "",
"sample" : [
{
"quantity" : 「1」,
}
]
}
的Json 2:
{
"Comments" : "test」,
"user_id" : 「test」,
"EdDate" : "08\/26\/2015 04:11:51 PM",
"StDate" : "08\/26\/2015 04:11:21 PM",
"latitude" : "",
"longitude" : "",
"sample" : [
{
"quantity" : 「1」,
}
]
}
我需要一個發一個。我使用下面的代碼,但只有一次我得到正確的迴應。
NSOperationQueue *mainQueue = [[NSOperationQueue alloc] init];
for(int i=0 ; i < [tempJsonFromDB count]; i++)
{
tempjsondata = [tempjsondata stringByAppendingString:tempJsonFromDB[i]];
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
[request setURL:[NSURL URLWithString:url]];
[request setValue:@"application/json" forHTTPHeaderField:@"Accept"];
[request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
[request setHTTPMethod:@"POST"];
[request setHTTPBody:[tempjsondata dataUsingEncoding:NSUTF8StringEncoding]];
[mainQueue setMaxConcurrentOperationCount:5];
[NSURLConnection sendAsynchronousRequest:request queue:mainQueue completionHandler:^(NSURLResponse *response,
NSData *urlData, NSError *requestError)
{
NSString* newStr1 = [NSString stringWithUTF8String:[urlData bytes]];
NSLog(@「string%@「,newStr1);
}];
NSURLConnection *connection = [[NSURLConnection alloc] initWithRequest:request delegate:self];
[connection start];
}
請問您能否描述請求的其餘部分會發生什麼,在completionHandler中是否出現錯誤,如果是,錯誤是什麼? –
這是你的陣列tempJsonFromDB –
@Abd Al-rhman Taher Badary第一次我得到「真實」但我得到一些網頁內容後。 – VJVJ