2012-05-16 103 views
-2

我有一個問題,我不明白是怎麼回事。它在一小時前工作,然後停止工作,我不明白爲什麼。 :s從JSON填充NSMutableArray - Empty = o

您能否將此JSON添加到本地主機上的文件夾中,然後嘗試這段代碼。然後可以做,如果告訴我你的NSLog打印的東西比這更好:

2012-05-16 11:18:21.996 WonderBox[51241:fb03] JSON : (null) 


NSString *urlString = [NSString stringWithFormat:@"http://localhost:8888/WonderBox/json.txt"]; 
    NSData *data = [NSData dataWithContentsOfURL:[NSURL URLWithString:urlString]]; 
    NSError *err; 
    NSMutableArray *json = (NSMutableArray*)[NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:&err]; 


    NSLog(@"JSON : %@", json); 

MY JSON:

{ 
    "boxesDetail": [ 
     { 
      "name": "NAME1", 
      "number": "12", 
      "sexe": "female", 
      "topic": "Bien-être", 
        }, 
     { 
      "name": "NAME2", 
      "number": "33", 
      "sexe": "couple", 
      "topic": "Bien-être", 
     }, 
     { 
      "name": "NAME3", 
      "number": "43", 
      "sexe": "female", 
      "topic": "Gastronomie", 

     }, 
      { 
      "name": "NAM E4", 
      "number": "33", 
      "sexe": "couple", 
      "topic": "Adventure", 
     }, 
      { 
      "name": "NAME5", 
      "number": "102", 
      "sexe": "group", 
      "topic": "Gastronomie", 
     }, 
      { 
      "name": "NAME6", 
      "number": "40", 
      "sexe": "male", 
       "topic": "Sport", 
     }, 
      { 
      "name": "NAME7", 
      "number": "12", 
      "sexe": "male", 
      "topic": "Sport", 
     } 


    ] 
} 

回答

0

你JSON是無效的,可以使用http://jsonlint.com/

不應該有在一個逗號每個topic關鍵的結束。

{ 
    "boxesDetail": [ 
     { 
      "name": "NAME1", 
      "number": "12", 
      "sexe": "female", 
      "topic": "Bien-être" <-- there should be no comma here 
     }, 
... 
+0

有一個昏迷,我發現問題:「名稱」:「NAM E4」,有一個空間,它不工作..但它很奇怪......爲什麼?它應該與空間... – user1256827

+0

找到答案...這是一個選項卡://對不起,男人! – user1256827