0

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}

JSONData

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
0yeoj
  • 4,500
  • 3
  • 23
  • 41
Jose
  • 1,027
  • 1
  • 14
  • 23
  • It seems to me the message is clear. Where are you doing initWithDictionary? – Hot Licks Nov 15 '13 at 18:50
  • BTW, what you list is not a dictionary. – Hot Licks Nov 15 '13 at 18:52
  • If you see the code at the beginning I am using initFromURLWithString not dictionary. – Jose Nov 16 '13 at 08:01
  • So where are you doing initWithDictionary, and what does the dictionary look like? Your error message says "Attempt to initialize JSONModel object using initWithDictionary:error: but the dictionary parameter was not an 'NSDictionary'". – Hot Licks Nov 16 '13 at 13:02
  • Again this is what I could not figure out why?, I never did initWithDictionary see to top code on my post I was using initFromURLWithString. – Jose Nov 16 '13 at 22:38

3 Answers3

1

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).

neutrino
  • 2,297
  • 4
  • 20
  • 28
  • Yes you was right regarding the LotDTO not being defined as array, I was hacking everywhere I miss that one, but I went for test and error and after commented all the properties and un-comenting one by one I found the the property "description" was breaking the feed so I just renamed my JSON to "descrip" and everything works! could be that "description" needs to be pointed as Reserved Word? – Jose Nov 16 '13 at 08:47
0

Make sure to mark any extension property as Ignore. I faced such an issue trying to copy the model.

Anupdas
  • 10,211
  • 2
  • 35
  • 60
0

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

Milan Manwar
  • 374
  • 3
  • 10