gpt4 book ai didi

ios - NSData 的内容到 NSArray/NSDictionary

转载 作者:行者123 更新时间:2023-11-29 13:19:48 24 4
gpt4 key购买 nike

我有这个:

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

NSURL *url = [NSURL URLWithString:@"http://www.xyz.com/ios/responseScript.php"];

NSError *error = nil;

NSURLRequest *request = [NSURLRequest requestWithURL:url];

NSData *data = [NSURLConnection sendSynchronousRequest:request returningResponse:NULL error:&error];

NSString *dataString = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];


}

当我打印 dataString 时,它显示的正是我所期望的,即

["Bannana","Apple","SomeCheese"]

我想把它处理成 NSMutableArray。我该怎么做?

谢谢,

最佳答案

试试这个:

NSDictionary *dictionary = [NSJSONSerialization JSONObjectWithData:returnData options:kNilOptions error:&error];
NSMutableArray *array = [[NSMutableArray alloc] init];
for(NSString *key in dictionary) {
[array addObject:[dictionary objectForKey:key]];
}

关于ios - NSData 的内容到 NSArray/NSDictionary,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14664760/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com