0

I'm getting a json parse error

Error Domain=NSCocoaErrorDomain Code=3840 "The operation couldn’t be completed. (Cocoa error 3840.)" (Invalid value around character 2.) 

Which means there is some problem in jSON response. But I'm facing a weird situation like I'm not getting this error when I'm using the local host url. If I'm using the staging server URL to fetch the json I'm getting this error. But the fact is the same file has been migrated to the staging server.

When I checked url in browser I'm getting same response for both the urls;.

This is my response

[
  {
    "ClinicId": 15,
    "ClinicNumber": "45-001",
    "Name": "TBD Utah",
    "PCName": "",
    "Address": "",
    "Address2": "",
    "City": "",
    "State": "UT        ",
    "Zipcode": "",
    "RegionId": 15,
    "Latitude": 0.0,
    "Longitude": 0.0,
    "MetroId": 0,
    "CoopId": 0,
    "PublicEmail": "",
    "PublicPhoneNumber": "",
    "ActualPhoneNumber": "",
    "ClinicOpenDate": "0001-01-01T00:00:00",
    "ClinicUrl": "",
    "Notes": ""
  },
  {
    ------
  },
  {
    ------
  },
]

This is the way i'm fetching the data

     NSString *str=@"http://192.2.200.167:84/api/Clinic/ClinicsByLatandLong?latitude=36.778261&longitude=-119.417932&apiKey=E9F5958F-C4BE-4D81-8649-F385205F0684";

    NSURL *aUrl = [NSURL URLWithString:str];
    NSMutableURLRequest *request = [[NSMutableURLRequest alloc]initWithURL:aUrl];
    [request setHTTPMethod:@"GET"];
    [request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
    NSURLConnection *connection= [[NSURLConnection alloc] initWithRequest:request
                                                           delegate:self];
   if (connection) {
        responseData=[NSMutableData data];
    }
4

1 回答 1

1

在解析响应之前,我建议您检查它(在代码中,而不是在 Web 浏览器中),例如:

NSLog(@"responseData = %@", [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding]);

我敢打赌,反应不是你想象的那样。Web 服务器报告了一些错误,或者您的didReceiveData.

您的分享不足以让我们对您的NSURLConnectionDataDelegate方法发表评论,但这NSLog将帮助您确认 JSON 响应实际上是您所期望的。

于 2013-09-18T06:30:31.320 回答