-2

我有一个问题,我不明白发生了什么。它在一小时前工作,然后停止工作,我不明白为什么。:秒

您能否将此 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",
        }


    ]
}
4

1 回答 1

0

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

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

{
    "boxesDetail": [
        {
            "name": "NAME1",
            "number": "12",
            "sexe": "female",
            "topic": "Bien-être" <-- there should be no comma here
        },
...
于 2012-05-16T09:37:42.890 回答