2013-03-26 27 views
0

我一直在嘗試使用JSONmodel嘗試從我的服務器獲取數據到我的ios設備。我已經正確地建立了我的類,但由於某種原因,它在調用url之後會一直返回null。使用JSONmodel嘗試從服務器獲取數據到ios設備

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 

與我的咖啡館類沿模型

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

的JSON輸出:

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

我一直試圖找出一段時間的解決方案並沒有拿出任何東西,我很難爲什麼這不工作。任何幫助都是極好的。

+0

難道是因爲URL中有2個'http://'嗎? – 2013-03-27 00:04:11

+0

請顯示JSON文件的一部分和JSON解碼代碼。 – Alex 2013-03-27 00:08:35

+0

@ChrisLoonam只是注意到,並刪除它,它仍然無法正常工作。當我檢查錯誤消息錯誤時會出現此錯誤操作無法完成。 (可可錯誤3840.) – user1179321 2013-03-27 00:10:16

回答

1

好吧,但是它看起來像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答案是告訴你具體是什麼問題。

+0

我總是使用這個網站:http://jsonlint.com - 它是超快的驗證一個json字符串,沒有廣告等(對SO總監:我不隸屬於他們,它是隻是非常有用的快速檢查的東西) – 2013-04-07 10:04:22

相關問題