簡體   English   中英

使用 Objective-c 在 iOS 中將 JSON 轉換為對象

[英]JSON to Object in iOS with objective-c

我有對象

@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

和網址

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

我不能通過 jsonmodel pod 將 json 添加到對象,因為列表中的天氣是一個數組。

@Ngọc Thái:我不太明白你的問題。 但是,如果您想從 JSON(包含對象數組)解析到對象。

簡單,你可以試試: https : //github.com/elado/jastor#arrays

希望這有幫助!

試試我的項目BWJSONMatcher 它可以幫助您輕松地將 json 字符串轉換為 NSArray:

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

該庫是完全開源的,並在 MIT 許可下。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM