Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/37.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 解析Json时出错_Iphone_Json - Fatal编程技术网

Iphone 解析Json时出错

Iphone 解析Json时出错,iphone,json,Iphone,Json,在解析json服务时,它第一次运行良好,但在第二次运行时,它给了我下面给出的错误 -JSONValue failed. Error trace is: ( "Error Domain=org.brautaset.JSON.ErrorDomain Code=11 \"Unexpected end of string\" UserInfo=0x5f57450 {NSLocalizedDescription=Unexpected end of string}" 提前谢谢 代码开始解析: NSSt

在解析json服务时,它第一次运行良好,但在第二次运行时,它给了我下面给出的错误

-JSONValue failed. Error trace is: (
"Error Domain=org.brautaset.JSON.ErrorDomain Code=11 \"Unexpected end of string\" UserInfo=0x5f57450 {NSLocalizedDescription=Unexpected end of string}"  
提前谢谢

代码开始解析:

NSString *urlString = [NSString stringWithFormat:@"http://ax.itunes.apple.com/WebObjects/MZStoreServices.woa/wa/wsSearch?term=%@",tt.text];
解析代码::

    - (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 {
    UIAlertView *alert =[[UIAlertView alloc]initWithTitle:@"error" message:@"Problem with parsing data" delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil];
    [alert show];
    [alert release];
    [UIApplication sharedApplication].networkActivityIndicatorVisible=NO;
    self.responseData = nil;
}
- (void)connectionDidFinishLoading:(NSURLConnection *)connection {
    NSString *responseString = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];
    self.responseData = nil;
    NSLog(@"%@",[responseString JSONValue]);
    NSArray* latestLoans = [(NSDictionary*)[responseString JSONValue] objectForKey:@"results"];
    [responseString release];
    NSLog(@"count === %d",[latestLoans count]);
        for (int i = 0; i < [latestLoans count]; i++)
        {
            NSLog(@" inside for loop %@",[latestLoans objectAtIndex:i]);
            NSDictionary* loan = [latestLoans objectAtIndex:i];
            NSLog(@" trackanme=== %@",[loan objectForKey:@"collectionName"]);
                NSLog(@" artworkurl=== %@",[loan objectForKey:@"artworkUrl60"]);
            [titlearray addObject:[loan objectForKey:@"collectionName"]];
            [imagelink addObject:[loan objectForKey:@"artworkUrl60"]];

        }
    //get latest loan

    NSLog(@"titlearray count == %d",[titlearray count]);
    NSLog(@"imagelink count ===%d",[imagelink count]);
    //fetch the data
    //NSString* fundedAmount = [loan objectForKey:@"Kind"];
    //NSNumber* loanAmount = [loan objectForKey:@"loan_amount"];
    //float outstandingAmount = [loanAmount floatValue] - [fundedAmount floatValue];

        //NSString* country = [(NSDictionary*)[loan objectForKey:@"location"] objectForKey:@"country"];

    //set the text to the label
    //label.text = [NSString stringWithFormat:@"Latest loan: %@ from %@ needs another $%.2f, please help",
    //            name,country,outstandingAmount
    //            ];    
    [UIApplication sharedApplication].networkActivityIndicatorVisible=NO;
    [tbl reloadData];
}


    NSLog(@"url ===%@",urlString);
    // Create NSURL string from formatted string, by calling the Flickr API
    NSURL *url = [NSURL URLWithString:urlString];


    // Setup and start async download
    NSURLRequest *request = [[NSURLRequest alloc] initWithURL: url];
    NSURLConnection *connection = [[NSURLConnection alloc] initWithRequest:request delegate:self];
    [connection release];
    [request release];

问题是,我没有很好地链接我的json框架,我尝试了github提供的新框架,但效果很好

感谢所有提出自己想法并引导我找到解决问题的正确方向的人


非常感谢………

如何解析json,在哪里解析json?一个json的例子也会很有帮助。我从链接开始第一次使用它很好,但是当我第二次做同样的事情时,它给出了错误。谢谢你的回复。你可以显示使用你开始解析的代码吗?我编辑了问题,它显示了我开始解析的代码。请发布进行解析的代码?您使用什么库来解析JSON?您介意提供新框架的链接吗?如果可能的话,您到底是如何解决这个问题的?事实上,我也有同样的问题..仅供参考:您也可以使用标准NS*库的一部分。这样,您就可以避免使用外部框架进行这种幼稚的转换。
-(IBAction)searchitem:(id)sender
{[UIApplication sharedApplication].networkActivityIndicatorVisible=YES;


[tt resignFirstResponder];

NSString *urlString = [NSString stringWithFormat:@"http://ax.itunes.apple.com/WebObjects/MZStoreServices.woa/wa/wsSearch?term=%@",tt.text];

NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:urlString]];
[[NSURLConnection alloc] initWithRequest:request delegate:self];


}