mysql - 使用此代码从 MySQL 数据库调用坐标会导致模拟器显示 SIGABRT 错误。怎么了?

标签 mysql json crash mkmapview sigabrt

当我使用此代码尝试从 MySQL 数据库调用 Lat & Long 坐标(并将它们显示在 MapView 上)时,应用程序运行良好。一切似乎都正常,但由于某种原因,xcode 在 map 加载之前暂停了模拟器,并向我抛出了一个 SIGABRT。知道为什么吗?见下文:

MapViewController.h

#import <UIKit/UIKit.h>
#import <MapKit/MapKit.h>


    @interface MapViewController : UIViewController  <MKMapViewDelegate> 

        @property (nonatomic, strong) IBOutlet MKMapView *mapView;
        @property (nonatomic, retain) NSMutableArray *dispensaries;
        @property (nonatomic, retain) NSMutableData *data;


    @end

MapViewController.m
#import "MapViewController.h"
#import "MapViewAnnotation.h"


    @implementation MapViewController
    @synthesize mapView;
    @synthesize dispensaries;
    @synthesize data;



    - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
    {
        self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
        if (self) {
            // Custom initialization
        }
        return self;
    }

    - (void)didReceiveMemoryWarning
    {
        // Releases the view if it doesn't have a superview.
        [super didReceiveMemoryWarning];

        // Release any cached data, images, etc that aren't in use.
    }

    #pragma mark - View lifecycle

    - (void)viewDidLoad {

    [super viewDidUnload];



            NSLog(@"Getting Device Locations");

            NSString *hostStr = @"http://stylerepublicmagazine.com/dispensaries.php";
            NSData *dataURL = [NSData dataWithContentsOfURL:[NSURL URLWithString:hostStr]];
            NSString *serverOutput = [[NSString alloc] initWithData:dataURL encoding: NSASCIIStringEncoding];
            NSLog(@"server output: %@", serverOutput);
            NSMutableArray *array = (NSMutableArray *)dispensaries;
            dispensaries = [NSJSONSerialization JSONObjectWithData:data options:nil error:nil];

            for (NSDictionary *dictionary in array) {



                CLLocationCoordinate2D coord = {[[dictionary objectForKey:@"lat"] doubleValue], [[dictionary objectForKey:@"lng"] doubleValue]};

                MapViewAnnotation *ann = [[MapViewAnnotation alloc] init];
                ann.title = [dictionary objectForKey:@"Name"];
                ann.coordinate = coord;
                [mapView addAnnotation:ann];



        [mapView setMapType:MKMapTypeStandard];
        [mapView setZoomEnabled:YES];
        [mapView setScrollEnabled:YES];



        self.mapView.delegate = self;


    }

    }

    - (void)mapView:(MKMapView *)mapView didUpdateUserLocation:(MKUserLocation *)userLocation

    {
        MKCoordinateRegion region = MKCoordinateRegionMakeWithDistance(userLocation.coordinate, 800, 800);
        [self.mapView setRegion:[self.mapView regionThatFits:region] animated:YES];


    MKPointAnnotation *point = [[MKPointAnnotation alloc] init];
    point.coordinate = userLocation.coordinate;
    point.title = @"You Are Here";
    point.subtitle = @"Your current location";

    [self.mapView addAnnotation:point];



    }

最佳答案

好的,现在你有了 JSON。您将不得不使用 NSXMLParser 对其进行解码。 .或者,如果你想把它变成对象,你可以使用我在 GitHub 上的开源库,它允许你简单地实现 NSCoding 协议(protocol)并将对象实例化(或将它们编码)为 JSON。那是here .

关于mysql - 使用此代码从 MySQL 数据库调用坐标会导致模拟器显示 SIGABRT 错误。怎么了?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14543777/

相关文章:

mysql - #1060 - 重复的列名称 'id'

json - 使用 RestTemplate 进行部分 JSON 检索

oracle - Tuxedo Client 12崩溃

java - 无法从数据库中检索数据

Mysql查询连接多个表的数据

mysql - UPDATE 查询更改了没有 WHERE 子句但有 AND 子句的行 - 为什么?

javascript - 如何将 JSON 内容放入 <ul> 标签并在 HTML 中形成

json - 将 json 格式的列转换为新的数据框

flash - Google App Engine上的Flash游戏崩溃(其中一些)

crash - 调用XtDestroyWidget时,主题应用程序崩溃