从JSON填充NSMutableArray - Empty = o

时间:2012-05-16 09:30:56

标签: objective-c ios json parsing

我遇到了问题,我不明白发生了什么。它工作一小时前然后停止工作,我不明白为什么。 :s

您能否在本地主机的文件夹中添加此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);

我的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",
        }


    ]
}

1 个答案:

答案 0 :(得分:0)

您的JSON无效,请使用http://jsonlint.com/

每个topic键的末尾都不应该有逗号。

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