【发布时间】:2012-09-02 21:44:26
【问题描述】:
我是 JSON 解析的新手。我正在使用 SBJson 3.1 并尝试获取数据以响应我遇到的上述错误。我在谷歌上搜索了很多,但没有人问过或解释过错误Illegal Start of Token 的实际含义。所以请有人可以解释一下吗?我该如何调试这个错误?
目前我写的代码是:
-(IBAction) Start:(id)sender
{
responseData = [[NSMutableData data] retain];
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:URL]];
[[NSURLConnection alloc] initWithRequest:request delegate:self];
}
-(void) connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
{
[responseData setLength:0];
}
-(void) connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{
[responseData appendData:data];
}
-(void) connection:(NSURLConnection *)connection didFailWithError:(NSError *)error
{
label.text = [NSString stringWithFormat:@"Connection failed: %@", [error description]];
[connection release];
responseData = nil;
}
-(void) connectionDidFinishLoading:(NSURLConnection *)connection
{
[connection release];
NSString *responseString = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];
[responseData release];
NSDictionary *dict = [responseString JSONValue];
}
【问题讨论】:
-
你的 JSON 输入是什么?
-
我只是提供 URL “xyz/Final/webserviceName.php” 来获取整个数据用于测试目的。
-
哦,是的,我可以完全用它来告诉你问题出在哪里。告诉我数据是什么怎么样?
-
数据格式为:[{"UserId":"1","UserName":"Mahnor ahmad","Address":"Block-l Naz, Kh","EmailId":" maha@xyz.com","Pswd":"1234567","Dob":"2012-06-05","Gender":"female","SecAns":"biryani","CountryId":"3" ,"城市":"卡拉奇","ProfessionId":"3","SecQId":"1","zip":"0"}]。还有很多这样的。
-
你确定这正是函数正在读取的内容吗?如果用输出函数替换 parse 函数,会得到这样的结果吗?
标签: json ios4 runtime-error sbjson