简体   繁体   中英

JSON to Object in iOS with objective-c

I have object

@interface Hourly (CoreDataProperties)

@property (nullable, nonatomic, retain) NSDate *dt;
@property (nullable, nonatomic, retain) NSNumber *temp;
@property (nullable, nonatomic, retain) NSNumber *temp_min;
@property (nullable, nonatomic, retain) NSNumber *temp_max;
@property (nullable, nonatomic, retain) NSNumber *humidity;
@property (nullable, nonatomic, retain) NSNumber *pressure;
@property (nullable, nonatomic, retain) NSString *main;
@property (nullable, nonatomic, retain) NSString *des;
@property (nullable, nonatomic, retain) NSString *icon;

@end

And url

http://api.openweathermap.org/data/2.5/forecast/dayly?lat=35&lon=139&cnt=2

I can' add json to object by jsonmodel pod because weather in list is a array .

@Ngọc Thái: I don't really understand your question. But, if you want parse from JSON (contain array of objects) to object.

Simple, you can try it: https://github.com/elado/jastor#arrays

Hope this help!

Try my project BWJSONMatcher . It helps you easily convert a json string to NSArray:

NSArray *dataArray = [BWJSONMatcher matchJSON:YOURJSONSTRING withClass:[Hourly class]];

The library is fully opensourced and under MIT license.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM