這是我傳遞給SBJsonStreamParserJSON解析器拋出錯誤,問題JSON字符串
{"ID":"6","UserID":"8","WeighedOn":"2/11/2011 ","Weight":"73.5"},{"ID":"9","UserID":"8","WeighedOn":"2/14/2011 ","Weight":"73.5"},{"ID":"15","UserID":"8","WeighedOn":"2/15/2011 ","Weight":"73.5"},{"ID":"25","UserID":"8","WeighedOn":"2/16/2011 ","Weight":"73.5"},{"ID":"46","UserID":"8","WeighedOn":"2/18/2011 ","Weight":"161.7"},{"ID":"47","UserID":"8","WeighedOn":"2/21/2011 ","Weight":"161.7"},{"ID":"99","UserID":"8","WeighedOn":"2/22/2011 ","Weight":"161.82"},{"ID":"134","UserID":"8","WeighedOn":"2/23/2011","Weight":"198"},{"ID":"158","UserID":"8","WeighedOn":"2/25/2011 ","Weight":"199.65"},{"ID":"189","UserID":"8","WeighedOn":"2/28/2011 ","Weight":"166.17"},{"ID":"220","UserID":"8","WeighedOn":"3/1/2011 ","Weight":"60"},{"ID":"231","UserID":"8","WeighedOn":"3/2/2011 ","Weight":"165"},{"ID":"271","UserID":"8","WeighedOn":"3/3/2011 ","Weight":"220"},{"ID":"281","UserID":"8","WeighedOn":"3/4/2011 ","Weight":"220"},{"ID":"302","UserID":"8","WeighedOn":"3/7/2011 ","Weight":"166.1"},{"ID":"316","UserID":"8","WeighedOn":"3/9/2011 ","Weight":"166.1"},{"ID":"325","UserID":"8","WeighedOn":"3/10/2011","Weight":"70"},{"ID":"334","UserID":"8","WeighedOn":"3/11/2011 ","Weight":"70"},{"ID":"343","UserID":"8","WeighedOn":"3/14/2011 ","Weight":"70"},{"ID":"353","UserID":"8","WeighedOn":"3/15/2011 ","Weight":"70"},{"ID":"358","UserID":"8","WeighedOn":"3/16/2011 ","Weight":"70"},{"ID":"371","UserID":"8","WeighedOn":"3/23/2011","Weight":"198"},{"ID":"377","UserID":"8","WeighedOn":"3/24/2011","Weight":"99"},{"ID":"437","UserID":"8","WeighedOn":"3/25/2011 ","Weight":"160"},{"ID":"472","UserID":"8","WeighedOn":"4/1/2011 ","Weight":"180"}
我將其轉換爲數據,並解析它,使用下面的代碼
str = [NSString stringWithFormat:@"{\"ID\":\"6\",\"UserID\":\"8\",\"WeighedOn\":\"2/11/2011 \",\"Weight\":\"73.5\"},{\"ID\":\"9\",\"UserID\":\"8\",\"WeighedOn\":\"2/14/2011 \",\"Weight\":\"73.5\"},{\"ID\":\"15\",\"UserID\":\"8\",\"WeighedOn\":\"2/15/2011 \",\"Weight\":\"73.5\"},{\"ID\":\"25\",\"UserID\":\"8\",\"WeighedOn\":\"2/16/2011 \",\"Weight\":\"73.5\"},{\"ID\":\"46\",\"UserID\":\"8\",\"WeighedOn\":\"2/18/2011 \",\"Weight\":\"161.7\"},{\"ID\":\"47\",\"UserID\":\"8\",\"WeighedOn\":\"2/21/2011 \",\"Weight\":\"161.7\"},{\"ID\":\"99\",\"UserID\":\"8\",\"WeighedOn\":\"2/22/2011 \",\"Weight\":\"161.82\"},{\"ID\":\"134\",\"UserID\":\"8\",\"WeighedOn\":\"2/23/2011\",\"Weight\":\"198\"},{\"ID\":\"158\",\"UserID\":\"8\",\"WeighedOn\":\"2/25/2011 \",\"Weight\":\"199.65\"},{\"ID\":\"189\",\"UserID\":\"8\",\"WeighedOn\":\"2/28/2011 \",\"Weight\":\"166.17\"},{\"ID\":\"220\",\"UserID\":\"8\",\"WeighedOn\":\"3/1/2011 \",\"Weight\":\"60\"},{\"ID\":\"231\",\"UserID\":\"8\",\"WeighedOn\":\"3/2/2011 \",\"Weight\":\"165\"},{\"ID\":\"271\",\"UserID\":\"8\",\"WeighedOn\":\"3/3/2011 \",\"Weight\":\"220\"},{\"ID\":\"281\",\"UserID\":\"8\",\"WeighedOn\":\"3/4/2011 \",\"Weight\":\"220\"},{\"ID\":\"302\",\"UserID\":\"8\",\"WeighedOn\":\"3/7/2011 \",\"Weight\":\"166.1\"},{\"ID\":\"316\",\"UserID\":\"8\",\"WeighedOn\":\"3/9/2011 \",\"Weight\":\"166.1\"},{\"ID\":\"325\",\"UserID\":\"8\",\"WeighedOn\":\"3/10/2011\",\"Weight\":\"70\"},{\"ID\":\"334\",\"UserID\":\"8\",\"WeighedOn\":\"3/11/2011 \",\"Weight\":\"70\"},{\"ID\":\"343\",\"UserID\":\"8\",\"WeighedOn\":\"3/14/2011 \",\"Weight\":\"70\"},{\"ID\":\"353\",\"UserID\":\"8\",\"WeighedOn\":\"3/15/2011 \",\"Weight\":\"70\"},{\"ID\":\"358\",\"UserID\":\"8\",\"WeighedOn\":\"3/16/2011 \",\"Weight\":\"70\"},{\"ID\":\"371\",\"UserID\":\"8\",\"WeighedOn\":\"3/23/2011\",\"Weight\":\"198\"},{\"ID\":\"377\",\"UserID\":\"8\",\"WeighedOn\":\"3/24/2011\",\"Weight\":\"99\"},{\"ID\":\"437\",\"UserID\":\"8\",\"WeighedOn\":\"3/25/2011 \",\"Weight\":\"160\"},{\"ID\":\"472\",\"UserID\":\"8\",\"WeighedOn\":\"4/1/2011 \",\"Weight\":\"180\"}"];
NSLog(@"Str: %@",str);
NSData * data1 = [str dataUsingEncoding:NSUTF8StringEncoding];
data = data1;
SBJsonStreamParserStatus status = [parser parse:data];
字符串
但是每當我解析它時,我都會遇到下面的錯誤。
Parser error: Token 'value separator' not expected before outer-most array or object
你們能告訴我,它是什麼,哪個是錯的?
在IOS 5.0中Apple包含NSJSONSerialization類,用於將JSON轉換爲Foundation對象並將Foundation對象轉換爲JSON。 請查看http://developer.apple.com/library/ios/#documentation/Foundation/Reference/NSJSONSerialization_Class/瞭解詳情 – Tieme 2011-12-25 14:20:05