Objective c 正在读取JSON,null

Objective c 正在读取JSON,null,objective-c,json,Objective C,Json,这是我的JSON { "name": "abe", } 这是我代码的一部分 self.fileRoot = [[NSBundle bundleForClass:[self class]] pathForResource:@"name" ofType:@"json"]; self.jsonString = [NSString stringWithContentsOfFile:self.fileRoot encoding:NSUTF8StringEncoding error:nil

这是我的JSON

{
"name": "abe",
}
这是我代码的一部分

    self.fileRoot = [[NSBundle bundleForClass:[self class]] pathForResource:@"name" ofType:@"json"];
    self.jsonString = [NSString stringWithContentsOfFile:self.fileRoot encoding:NSUTF8StringEncoding error:nil];
    self.jsonParser = [[SBJsonParser alloc] init];
    self.dict = [self.jsonParser objectWithString:self.jsonString];    
    NSLog(@"\njsonString: %@\njsonParser: %@\ndict: %@\n", self.jsonString, self.jsonParser, self.dict);
日志是:

jsonString: {
    "name": "abe",
}
jsonParser: <SBJsonParser: 0x8d6b7f0>
dict: (null)
jsonString:{
“姓名”:“abe”,
}
jsonParser:
dict:(空)
我有个问题,这就是为什么dict说“(空)” 我敢肯定,当我上次(大约3个月前)测试它时,这段代码可以正常工作
有什么建议吗?提前感谢。

从键值对中删除逗号,因为json字符串中只有一个名称-值对

//convert string to NSData
NSString* str = @"{'name':'abe'}";
NSData* data = [str dataUsingEncoding:NSUTF8StringEncoding];

//create dictionary
NSError *error = nil;
NSDictionary *dict = [NSJSONSerialization
                        JSONObjectWithData: data
                        options:0
                        error:&error];

NSLog(@"Name: %@", dict[@"name"]);

在JSON中,大括号前不能有逗号。逗号位于数组或对象的元素之间,但不在它们的末尾。谢谢您的快速回答。我对它进行了编辑,但似乎没有任何改变。self.dict仍然说(null)这解决了我的问题>\uu \<你能告诉我为什么以前工作的代码会导致这个问题吗?顺便说一句,非常感谢!!!