JSON 解析问题

JSON Parshing issue

我从 Web 服务解析 JSON 值,但它给我这个错误:

Error Domain=NSCocoaErrorDomain Code=3840 "The operation couldn’t be completed (Invalid value around character 3.) UserInfo=0x7f97d5808540 {NSDebugDescription=Invalid value around character 3.}

NSURLSessionConfiguration *defaultConfigObject = [NSURLSessionConfiguration defaultSessionConfiguration];
    NSURLSession *defaultSession= [NSURLSession sessionWithConfiguration: defaultConfigObject delegate: self delegateQueue:[NSOperationQueue mainQueue]];
NSURLRequest *request = ConstructUrlRequestForuploadImage(DocumentManagementEntityMobileEntity,FileData);

NSLog(@"Response:-%@",request);
NSURLSessionDataTask *getNetworksTask;

getNetworksTask = [defaultSession dataTaskWithRequest:request
                                    completionHandler:^(NSData *data, NSURLResponse *response, NSError *error)
                   {
                       if (error)
                           NSLog(@"Error: %@ %@", error, [error userInfo]);

                       NSError *errorReturned = nil;
                       NSLog(@"Responce:-%@",response);

                       //   NSLog(@"Responce:-%@",response);
                       NSArray *dict = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingAllowFragments error:&errorReturned];

                       if (!dict) {
                           NSLog(@"Error parsing JSON: %@", errorReturned);
                       } else {
                           for(NSDictionary *item in dict) {
                               NSLog(@"Item: %@", item);
                           }
                       }

请帮助我。我会感谢你的。

空响应数组会出现此错误。因此,您应该更改 json 响应格式,例如 {status = 1, data = [] }。在您的情况下,没有数据响应是 []。所以这会在 json 解析时出错。您可以根据数据更改状态值,例如 0 或 1。