0

I've been trying to use JSONmodel to try and get data from my server to my ios device. I've set up my classes properly but for some reason it keeps coming back null after calling the url.

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);

Here is the model that holds the feeds

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

along with my coffee shop class

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

the json output:

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

i've been trying to find a solution for a while and have come up with nothing and im stumped on why this isnt working. Any help would be awesome.

Marin Todorov
  • 6,377
  • 9
  • 45
  • 73
user1179321
  • 797
  • 1
  • 10
  • 24

1 Answers1

1

Ok, well it looks like the JSON has some thing wrong with it because I tried this code

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);
}

and it returns

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

So, if it's your website, I'd change the JSON to a valid format, or contact the owner of the website and notify them of the problem. This answer is tells you what the problem is specifically.

Community
  • 1
  • 1
Chris Loonam
  • 5,735
  • 6
  • 41
  • 63
  • I always use this web site: http://jsonlint.com - it's super fast to validate a json string, no ads, etc. (to the SO overlords: I am not affiliated with them, it's just very useful to quickly check stuff) – Marin Todorov Apr 07 '13 at 10:04