gpt4 book ai didi

ios - 如何从这种类型的json格式中获取数据?

转载 作者:行者123 更新时间:2023-11-28 17:50:50 28 4
gpt4 key购买 nike

我的 JSON 是给定的格式

{
"BL_NO": "CSV*******13",
"LOADING_PORT": "YANTAI",
"DISCHARGE_PORT": "YINGKOU",
"DELIVERY_PLACE": "YINGKOU"
}

我正在尝试使用下面给出的代码:

NSString *str =[NSString stringWithFormat:@"http://wcfshiptracker.logistify.net/ShipmentTrackingService.svc/FetchData/ChinaShipping-bl_no-TGHU6571642"];
NSURL *url = [NSURL URLWithString:str];
NSData *data = [NSData dataWithContentsOfURL:url];
NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:nil];
aryother = [dict valueForKey:@"BL_NO"];

最佳答案

您的 JSON 格式不正确,它给出的字符串不是字典。请使用这个

NSString *str =[NSString stringWithFormat:@"http://wcfshiptracker.logistify.net/ShipmentTrackingService.svc/FetchData/ChinaShipping-bl_no-TGHU6571642"];
NSURL *url = [NSURL URLWithString:str];
NSData *data = [NSData dataWithContentsOfURL:url];
NSString *str3= [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingAllowFragments error:nil];
NSError *jsonError;
NSData *objectData = [str3 dataUsingEncoding:NSUTF8StringEncoding];
NSMutableDictionary *dict3 = [NSJSONSerialization JSONObjectWithData:objectData
options:NSJSONReadingAllowFragments
error:&jsonError];

NSString *a = [dict3 valueForKey:@"BL_NO"];

关于ios - 如何从这种类型的json格式中获取数据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38343432/

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