0
我正在嘗試使用JSON來解析PHP文件的某些輸出,希望能夠從我的MySQL數據庫返回一些數據。但是,我收到錯誤:-JSONValue失敗。錯誤是:令牌[A]的非法啓動。 php腳本返回一個用於在地圖上標註註釋的字典數組。我究竟做錯了什麼?使用JSON和PHP的iOS錯誤
- (void)getDeviceLocations {
NSLog(@"Getting Device Locations");
NSString *hostStr = @"http://98.246.50.81/firecom/api/getdevicelocations.php";
NSData *dataURL = [NSData dataWithContentsOfURL:[NSURL URLWithString:hostStr]];
NSString *serverOutput = [[NSString alloc] initWithData:dataURL encoding: NSASCIIStringEncoding];
id object = [serverOutput JSONValue];
NSMutableArray *array = (NSMutableArray *)object;
for (NSDictionary *dictionary in array) {
CLLocationCoordinate2D coord = {[[dictionary objectForKey:@"latitude"] doubleValue], [[dictionary objectForKey:@"longitude"] doubleValue]};
Annotation *ann = [[Annotation alloc] init];
ann.title = [dictionary objectForKey:@"deviceid"];
ann.coordinate = coord;
[mapView addAnnotation:ann];
}
}
請張貼JSON,我認爲這是一個無效的JSON –
我訪問的URL,這是什麼retured: 陣列([0] =>陣列([設備ID] => E19的iPad [緯度] => 45.511293 [經度] => -122.800233)[1] =>陣列([deviceid] => E05 iPad [latitude] => 45.54580829752314 [經度] => -122.9588931798935)[2] => Array([deviceid] => E01 iPad [latitude] => 45.520697139998525 [longitude] => -122.98941537737846)) 我認爲這不是有效的JSON。 – onevcat