Reputation: 1067
I have this Json out of ASP MVC API I have the InvModel and the LotModel
but when I call
_InvFeed = [[InvModel alloc] initFromURLWithString:@"http://192.168.1.206/service/api/dto/inventory/1?p=Red%20Globe"
completion:^(JSONModel *model, JSONModelError *err)
{
NSLog(@"Inventory: %@", _InvFeed );
NSLog(@"Error: %@",err);
}];
I can not figure out this error:
Error: Error Domain=JSONModelErrorDomain Code=1 "Invalid JSON data: Attempt to initialize JSONModel object using initWithDictionary:error: but the dictionary parameter was not an 'NSDictionary'."
UserInfo=0x109075ff0 {NSLocalizedDescription=Invalid JSON data: Attempt to initialize JSONModel object using initWithDictionary:error: but the dictionary parameter was not an 'NSDictionary'., kJSONModelKeyPath=LotDTO}
and here are the JSONModels for: LotDTO
#import "JSONModel.h"
@interface InvLotModel : JSONModel
@property (assign, nonatomic) int lotid;
@property (strong, nonatomic) NSDate* expdate;
@property (strong, nonatomic) NSString* lotserial;
@property (strong, nonatomic) NSDate* lastupddate;
@property (strong, nonatomic) NSString<Optional>* providerlotserial;
@property (assign, nonatomic) NSDecimal* qtyoriginal;
@property (assign, nonatomic) NSDecimal* qtyallocated;
@property (assign, nonatomic) NSDecimal* qtyavailable;
@property (assign, nonatomic) NSDecimal* qtyonhand;
@property (strong, nonatomic) NSDate* receiptdate;
@property (strong, nonatomic) NSString* linecomment;
@property (assign, nonatomic) NSDecimal* unitcost;
@property (strong, nonatomic) NSString* warehouse;
@end
And here the Inventory Model
#import "JSONModel.h"
#import "InvLotModel.h"
@protocol InvModel @end
@interface InvModel : JSONModel
@property (assign, nonatomic) int id;
@property (strong, nonatomic) NSString* itemid;
@property (strong, nonatomic) NSString* description;
@property (strong, nonatomic) NSDate* createdate;
@property (strong, nonatomic) NSString* createuser;
@property (assign, nonatomic) float lastcost;
@property (assign, nonatomic) BOOL monitorlevel;
@property (assign, nonatomic) int minlevel;
@property (assign, nonatomic) int maxlevel;
@property (strong, nonatomic) NSString* gtin;
@property (assign, nonatomic) float weight;
@property (strong, nonatomic) NSString* uom;
@property (strong, nonatomic) NSString* sizes;
@property (strong, nonatomic) NSString* variety;
@property (strong, nonatomic) NSString <Optional>* bag;
@property (strong, nonatomic) NSString* style;
@property (strong, nonatomic) NSString* box;
@property (strong, nonatomic) NSString* label;
@property (strong, nonatomic) NSString* commodity;
@property (strong, nonatomic) InvLotModel* LotDTO;
@end
Upvotes: 0
Views: 3114
Reputation: 374
Please replace this
@property (strong, nonatomic) InvLotModel* LotDTO;
with this
@property (strong, nonatomic) NSArray<InvLotModel,ConvertOnDemand>* LotDTO;
As officials at JSONModel suggest to use ConvertOnDemand to convert NSArray to JSONModelArray in one of their tutorial to avoid error in implenentation.
This may help you : Click here
Upvotes: 0
Reputation: 10201
Make sure to mark any extension property as Ignore
. I faced such an issue trying to copy the model.
Upvotes: 0
Reputation: 2317
I see two problems:
1) In the InvModel
class, yo have defined LotDTO
as a single object, not an array.
2) In the JSON response you have posted, the syntax for LotDTO
does not seem to me valid JSON. It appears to be an array of LotDTO
objects, but it does not follow the syntax for JSON arrays (which you can check, for example, here).
Upvotes: 1