1
fand ich einen Code-Schnipsel here, die ich verwenden wollte, aber ich kann nicht herausfinden, wie es „string“ zurück zu machen und sehen, ob es funktioniert ...JSON-String in iOS5
// some strings for test
NSString *cpu = [[NSString alloc] initWithFormat:@"%.0f", [_cpuSlider value]];
NSString *ram = [[NSString alloc] initWithFormat:@"%.0f", [_ramSlider value]];
NSString *hdd = [[NSString alloc] initWithFormat:@"%.0f", [_hddSlider value]];
// put them into dictionary
NSDictionary *test = [NSDictionary dictionaryWithObjectsAndKeys:cpu, @"CPU", ram, @"RAM", hdd, @"HDD", nil];
// start of the code from page above
NSMutableData *myData = [[NSMutableData alloc]init];
NSKeyedArchiver *archiver = [[NSKeyedArchiver alloc]initForWritingWithMutableData:myData];
[archiver encodeObject:test forKey:@"MyKEY"];
[archiver finishEncoding];
id testJson = [NSJSONSerialization JSONObjectWithData:myData options:0 error:nil];
// end of code
// HERE I'd like know what to put in to see it as a string..e.g. { "CPU"=value; etc...}
UIAlertView *av = [[UIAlertView alloc] initWithTitle:@"MLIA" message:????? delegate:nil cancelButtonTitle:@"Zavřít" otherButtonTitles: nil];
[av show];
Vielen Dank!
Das ist so genial einfach! Danke vielmals! Was meinst du "Vergiss nicht die Autorelease"? Ich bin ziemlich neu in der iOS-Entwicklung, aber ist das nicht dank ARC veraltet? – Michal
Wenn Sie ARC verwenden, dann können Sie (ja!) Die Freigabe überspringen. Nicht jeder verwendet ARC aufgrund von Legacy-Code und Bibliotheken. –
@MarceloCantos möchten Sie vielleicht darauf hinweisen, was genau hier veröffentlicht werden muss. In diesem Fall ist es die Zeichenfolge 'repr', da sie mit einem alloc-init erstellt wurde. Das Json-Objekt sollte ein Autoreleased-Objekt nach meinem Verständnis sein. – pnizzle