我需要使用 JSON 提取数据,然后将它们放入 UITableView,但是当我尝试提取它们时出现此错误。
-JSONValue failed. Error is: Illegal start of token [E]
网站里的数据很多,10万多条,也许太多了?我的代码:
#import <UIKit/UIKit.h>
#import "SBJson.h"
@interface ProductsViewController : UIViewController <UITableViewDataSource, UITableViewDelegate, NSURLConnectionDataDelegate> {
NSURLConnection *conn;
NSMutableData *webData;
}
在 ProductsViewController.m
- (void)viewDidLoad
{
[super viewDidLoad];
NSURL *url=[NSURL URLWithString:@"http://www.e-xxxxxxx.it/virtualShop/pageflow/address/xxxxxxxxxxxx.do?json=true&vsIdxxxxxxxxxxxxxxxxxxxxxxxxxx=Ext.data.JsonP.callback1"];
NSMutableURLRequest *req = [NSMutableURLRequest requestWithURL:url];
conn =[[NSURLConnection alloc]initWithRequest:req delegate:self];
if(conn){
webData =[[NSMutableData alloc]init];
}
}
-(void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response{
[webData setLength:0];
}
-(void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data{
[webData appendData:data];
}
-(void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error{
NSLog(@"Connection failed: %@", [error description]);
}
-(void)connectionDidFinishLoading:(NSURLConnection *)connection{
NSLog(@" the number of data is %d", [webData length]);
//the number of data is 104557
NSString *strResult =[[NSString alloc]initWithData:webData encoding:NSUTF8StringEncoding];
NSDictionary *result =[strResult JSONValue];//the error is here
for (id obj in result){
NSLog(@"%@", result);
}
}
他的字符串strResult很长,这是一段
Ext.data.JsonP.callback1(
{ "urlId": "spesa-che-non-pesa-root",
"children" :
[{ "urlId": "9950000123511",
"label" : "I dolci della Pasqua" ,
"hasWideIcon" : false ,
"hasArticles" :false,
"children" : [{ "urlId": "9950000123512",
"label" : "Colombe" ,
"hasWideIcon" : false ,
"hasArticles" :false,
"children" : [{ "urlId": "9950000123513",
"label" : "Tradizionali" ,
"hasWideIcon" : false ,
"hasArticles" :true},
{ "urlId": "9950000123514",
"label" : "Farcite e ricoperte" ,
"hasWideIcon" : false ,
"hasArticles" :true},
{ "urlId": "9950000123515",
"label" : "Piccole" ,
"hasWideIcon" : false ,
"hasArticles" :true}]},
{ "urlId": "9950000123516",
"label" : "Torte " ,
"hasWideIcon" : false ,
"hasArticles" :true},
{ "urlId": "9950000123517",
"label" : "Uova al latte" ,
"hasWideIcon" : false ,
"hasArticles" :true},
{ "urlId": "9950000123522",
"label" : "Cioccolatini e Dolciumi" ,
"hasWideIcon" : false ,
"hasArticles" :true}]}