2016-07-26 12 views
0

Ich arbeite derzeit an einem Videobearbeitungsteil, wo ich die Screenshots und einige Schlüsselwerte im Wörterbuch erfassen. Am Ende der Aufnahme habe ich eine Reihe von Wörterbüchern.Upload Array von Wörterbüchern auf den Server und dann herunterladen

Jetzt möchte ich dieses Array von Wörterbuch auf einen Server hochladen und später möchte ich dieses Array herunterladen.

Ich habe versucht, NSMutableArray in Bytes zu konvertieren und schreibe es in Textdatei und dann lade ich die Textdatei herunter und wandle sie zurück in NSMutableArray.

Das Problem ist, dass die Wörterbücher in diesem NSMutableArray keine Schlüsselwerte haben.

Gibt es noch eine andere Möglichkeit, diese Informationen auf einen Server hochzuladen und herunterzuladen?

+0

können Sie Ihren Code einfügen? –

+0

Warum konvertieren Sie Ihr Array nicht in NSData? Veröffentlichen Sie es auf dem Server und nach dem Herunterladen können Sie Ihre Daten wieder in JSON konvertieren, so dass Sie es leicht analysieren können. –

Antwort

0

Sie sollten Ihre Informationen und Bilder trennen. Dann laden Sie sie hoch.

ein Beispiel:

- (void)viewDidLoad { 
[super viewDidLoad]; 
// Do any additional setup after loading the view, typically from a nib. 

//------------------This part is for upload------------------ 
//Upload info 
UIImage* sourceImage = [UIImage imageNamed:@"source.png"]; 
UIImageView* imgV1 = [[UIImageView alloc] initWithFrame:CGRectMake(50, 50, 100, 100)]; 
imgV1.backgroundColor = [UIColor redColor]; 
imgV1.image = sourceImage; 
[self.view addSubview:imgV1]; 

NSDictionary* uploadDic = [[NSDictionary alloc] initWithObjectsAndKeys: 
          @"source.png",@"testImage", 
          nil]; 
NSData* uploadData = [NSJSONSerialization dataWithJSONObject:uploadDic options:NSJSONWritingPrettyPrinted error:nil]; 
NSString* uploadString = [[NSString alloc] initWithData:uploadData encoding:NSUTF8StringEncoding]; 

//Upload image 
NSData* imageData = [NSData dataWithContentsOfFile:@"source.png"]; 
[self uploadInfoToURL:uploadString andImageData:imageData]; 
//----------------------------------------------------------- 

//------------------This part is for upload------------------ 
//Download info 
NSString *downLoadString = uploadString; 
NSData* downLoadData = [downLoadString dataUsingEncoding:NSUTF8StringEncoding]; 
NSDictionary *downLoadDic = [NSJSONSerialization JSONObjectWithData:downLoadData options:NSJSONReadingMutableContainers error:nil]; 
UIImageView* imgV2 = [[UIImageView alloc] initWithFrame:CGRectMake(50, 250, 100, 100)]; 
imgV2.backgroundColor = [UIColor blueColor]; 
[self.view addSubview:imgV2]; 

//Download image 
NSString* downURL = [NSString stringWithFormat:@"http://youServer/%@",[downLoadDic objectForKey:@"testImage"]]; 
imgV2.image = [self getImageFromURL:downURL]; 
//----------------------------------------------------------- 
} 

-(UIImage *) getImageFromURL:(NSString *)fileURL { 
NSLog(@"Begin download"); 
UIImage * result; 
NSData * data = [NSData dataWithContentsOfURL:[NSURL URLWithString:fileURL]]; 
result = [UIImage imageWithData:data]; 
return result; 
} 

-(BOOL *) uploadInfoToURL:(NSString *)infoString andImageData:(NSData *)data { 
NSLog(@"Begin upload"); 
//Use http post to upload your image data to you server 
// if (nil == error) { 
//  return YES; 
// } 
return NO; 
} 

Hoffe, es kann Ihnen helfen.

+0

Es kann Hunderte von Bildern auf einmal geben – Testiphone