I have a PHP Webservice that returns a JSON string with this format:
[{"latitud":"37.995914","longitud":"-1.139705","nombre":"Miguel de
Unamuno"},{"latitud":"37.995433","longitud":"-1.140143","nombre":"Calle
Pina"},{"latitud":"37.99499","longitud":"-1.140361","nombre":"Calle
Moncayo"},{"latitud":"37.993918","longitud":"-1.139392","nombre":"Calle
Moncayo2"},{"latitud":"37.994588","longitud":"-1.138543","nombre":"Calle
Salvador de Madriaga"}]
In my project, I have a custom class with the next structure:
#import <Foundation/Foundation.h>
#import <MapKit/MapKit.h>
@interface PCoordenada : NSObject
@property (nonatomic) CLLocationCoordinate2D *punto;
@property (nonatomic,strong) NSString *nombre;
@end
Then, I´m using other class for the main app:
#import <UIKit/UIKit.h>
#import "PCoordenada.h"
@interface TestViewController : UIViewController
@property (nonatomic,strong) NSData * HTTPResponse;
@property (nonatomic,strong) NSDictionary * dic;
@property (nonatomic,strong) NSMutableArray *arrayCoord;
@property (nonatomic,strong) PCoordenada *coor;
-(IBAction)GetDataFrom:(id)sender;
@end
I wonder how I can make a array of PCoordenada’s objects that contain the info of JSON string.
Anyone could help me?
Thanks in advance 🙂
Do this:
which will put the JSON into an NSArray of objects. Each of these objects is an NSDictionary. So then you just need to loop through the NSArray to get out the NSDictionary of each.
Each NSDictionary that you get from the loop holds the JSON properties as a key in the NSDictionary: