gpt4 book ai didi

ios - 获取没有括号的值

转载 作者:行者123 更新时间:2023-11-29 12:57:43 26 4
gpt4 key购买 nike

NSString *urlPath=[NSString stringWithFormat:@"http://maps.googleapis.com/maps/api/directions/json?origin=%f,%f&destination=%f,%f&sensor=false",coordinate1.latitude,coordinate1.longitude,coordinate2.latitude,coordinate2.longitude];

//NSLog(@"the url for searching is : %@",urlPath);
NSURL *url=[NSURL URLWithString:urlPath];
NSData *data=[NSData dataWithContentsOfURL:url];
NSDictionary *object = [NSJSONSerialization JSONObjectWithData:data options:0 error:nil];
NSNumber *results = [[[[object valueForKey:@"routes"]valueForKey:@"legs"]valueForKey:@"distance"]valueForKey:@"value"];

NSLog(@"Count %@",results);

结果如下:

(
(
12078
)
)

能不能把号码拿出来?

最佳答案

查看 Google API 的 map 我可以看出,路线包含路段,路段具有距离属性。

{
"status": "OK",
"routes": [ {
"summary": "I-40 W",
"legs": [ {
"steps": [ {
"travel_mode": "DRIVING",
"start_location": {
"lat": 41.8507300,
"lng": -87.6512600
},
"end_location": {
"lat": 41.8525800,
"lng": -87.6514100
},
"polyline": {
"points": "a~l~Fjk~uOwHJy@P"
},
"duration": {
"value": 19,
"text": "1 min"
},
"html_instructions": "Head \u003cb\u003enorth\u003c/b\u003e on \u003cb\u003eS Morgan St\u003c/b\u003e toward \u003cb\u003eW Cermak Rd\u003c/b\u003e",
"distance": {
"value": 207,
"text": "0.1 mi"
}
},
...
... additional steps of this leg
...
... additional legs of this route
"duration": {
"value": 74384,
"text": "20 hours 40 mins"
},
"distance": {
"value": 2137146,
"text": "1,328 mi"
},
"start_location": {
"lat": 35.4675602,
"lng": -97.5164276
},
"end_location": {
"lat": 34.0522342,
"lng": -118.2436849
},
"start_address": "Oklahoma City, OK, USA",
"end_address": "Los Angeles, CA, USA"
} ],

所以第一条路线第一段的距离应该是:

NSNumber *distance = object[@"routes"][0][@"legs"][0][@"distance"][@"value"];

关于ios - 获取没有括号的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20623675/

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