-JSONValue失败。错误是:非法启动令牌[E]

时间:2013-03-11 17:05:22

标签: iphone ios json runtime-error

我需要使用JSON提取数据然后将它们放在UITableView中,但是当我尝试提取它们时出现此错误。

 -JSONValue failed. Error is: Illegal start of token [E]

网站上的数据很多,超过100,000,可能太多了? 我的代码:

 #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}]}

1 个答案:

答案 0 :(得分:1)

如果您甚至看到响应......难道您没有看到不是JSON?

它包含在JavaScript回调函数中。 web服务基本上会向您返回错误的响应。