gpt4 book ai didi

ios - 提取不同格式的JSON数据

转载 作者:行者123 更新时间:2023-11-28 19:48:43 25 4
gpt4 key购买 nike

我正在尝试获取数组中的 JSON 响应,但我只想要没有索引的数据。这是我的代码:

NSString *myRequestString = [NSString stringWithFormat:@"getSetAvailability=yes&userId=41"];

// Create Data from request
NSData *myRequestData = [NSData dataWithBytes: [myRequestString UTF8String] length: [myRequestString length]];
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL: [NSURL URLWithString: @"http://Crux.solutions:giggy@182.184.71.153:81/Giggy/getUser.php"]];
// set Request Type
[request setHTTPMethod: @"POST"];
// Set content-type
[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"content-type"];
// Set Request Body
[request setHTTPBody: myRequestData];
// Now send a request and get Response
NSData *returnData = [NSURLConnection sendSynchronousRequest: request returningResponse: nil error: nil];
// Log Response
NSString *response = [[NSString alloc] initWithBytes:[returnData bytes] length:[returnData length] encoding:NSUTF8StringEncoding];
NSLog(@"%@",response);



NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:returnData options:NSJSONReadingMutableLeaves error:nil];
NSArray *Sunday=[dict objectForKey:@"Sunday"];
NSLog(@"Sunday: %@",[Sunday description]);

得到这样的响应:

{"Sunday": {"0": "1 AM", "1": "3 AM", "2": "2 AM", "3": "12 AM", "4": "5 AM", "5": "4 AM", "6": "6 AM"}, "Monday": {"0": "1 AM", "1": "3 AM", "2": "2 AM", "3": "12 AM", "4": "5 AM"}, "Tuesday": {"0": "1 AM", "1": "3 AM", "2": "2 AM", "3": "12 AM", "4": "5 AM"}, "Wednesday": {"0": "1 AM", "1": "3 AM", "2": "2 AM", "3": "12 AM", "4": "5 AM"}, "Thursday": {"0": "1 AM", "1": "3 AM", "2": "2 AM", "3": "12 AM", "4": "5 AM"}, "Friday": {}, "Saturday": {}}

特别是这样的星期天数组:

Sunday: {
0 = "1 AM";
1 = "3 AM";
2 = "2 AM";
3 = "12 AM";
4 = "5 AM";
5 = "4 AM";
6 = "6 AM";
}

我希望我的数组像 [@"1 AM", @"3AM",@"2AM"...]

最佳答案

试试这段代码

NSArray *Sunday=[[dict objectForKey:@"Sunday"] allValues];
NSLog(@"Sunday: %@",[Sunday description]);

关于ios - 提取不同格式的JSON数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30434452/

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