gpt4 book ai didi

php - 使用 JSONmodel 尝试从服务器获取数据到 ios 设备

转载 作者:行者123 更新时间:2023-11-29 04:02:59 25 4
gpt4 key购买 nike

我一直在尝试使用 JSONmodel 来尝试将数据从我的服务器获取到我的 ios 设备。我已经正确设置了我的类,但由于某种原因,它在调用 url 后一直返回 null。

feed = [[Feeds alloc] initFromURLWithString:@"http://http://www.cs4768project.net76.net/untitled.php?action=getShops"
completion:^(JSONModel *model, JSONModelError *err) {
NSLog(@"reached");
//json fetched
NSLog(@"shops: %@", feed.shops);

这是保存提要的模型

@interface Feeds : JSONModel
@property(strong,nonatomic) NSArray* shops;
@end

和我的咖啡店类(class)一起

@interface CoffeeShop : JSONModel
@property(strong, nonatomic) NSString* name;
@property(nonatomic) CLLocationDegrees latitude;
@property(nonatomic) CLLocationDegrees longtitude;
@end

json 输出:

{"name":"Starbs","latitude":"45","longtitude":"-52"}

我已经尝试寻找解决方案有一段时间了,但一无所获,我很困惑为什么这不起作用。任何帮助都会很棒。

最佳答案

好吧,看起来 JSON 有问题,因为我尝试了这段代码

NSError *e;
NSDictionary *s = [NSJSONSerialization JSONObjectWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:@"http://www.cs4768project.net76.net/untitled.php?action=getShops"]] options:NSJSONReadingMutableLeaves error:&e];
NSLog(@"%@", s);
if (e) {
NSLog(@"%@", e);
}

它返回

Domain=NSCocoaErrorDomain Code=3840 "The operation couldn’t be completed. (Cocoa error 3840.)" (Garbage at end.) UserInfo=0x1e0529f0 {NSDebugDescription=Garbage at end.}

因此,如果这是您的网站,我会将 JSON 更改为有效格式,或者联系网站所有者并通知他们问题。 This答案是告诉你问题具体是什么。

关于php - 使用 JSONmodel 尝试从服务器获取数据到 ios 设备,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15649592/

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