NSJSONSerialization won't map your JSON data to your custom class. It will provide NSString, NSNumber, NSDictionary, and NSArray objects (or their mutable counterparts, if you specify the right NSJSONReadingOptions).
If you want to map this data to your Parameters class, you have to provide that logic yourself. You cannot simply cast NSDictionary.
for(NSObject *obj in resultArray){
Parameters *paritem = [[Parameters alloc] init];
paritem.PAR_VPARAM = obj[@"PAR_VPARAM"];
paritem.PAR_VALUE = obj[@"PAR_VALUE"];
// To capture the IDI property, you will either have to
// define a new IDI class with a property named "IDI_ID",
// live with NSDictionary, or add an "IDI_ID" property
// to your Parameters class.
// In this example, I left the value as a dictionary.
paritem.IDI = obj[@"IDI"];
// Here's how you would get the IDI_ID:
NSNumber *IDI_ID = paritem.IDI[@"IDI_ID"];
}
With that out of the way, here are a couple unsolicited stylistic tips:
- For variables and properties in Obj-C, lowerCamelCase is conventional. Instead of
paritem.PAR_VPARAM, use parItem.parVParam (note the capital I in parItem).
- Your class names should have a two- or three-letter "namespace" (much like
NSString, UIView, or CGPoint). If you can't come up with a couple letters to represent this specific project, use an abbreviation of your company's name. If all else fails, use your initials.
- Your parameter names are extremely vague, and somewhat redundant. Does every property really need to be prefixed with
PAR_? Do you really need IDI_ID to be nested within the IDI property of your Parameters object? You could make your code much more readable by being more concise.
Here's what your code might look like if you took this advice (I'm making some assumptions of your source data):
for(NSObject *obj in resultArray){
APParameters *parItem = [[APParameters alloc] init];
parItem.parameterName = obj[@"PAR_VPARAM"];
parItem.parameterValue = obj[@"PAR_VALUE"];
// To capture the IDI property, you will either have to
// define a new IDI class with a property named "IDI_ID",
// live with NSDictionary, or add a property to your
// Parameters class which holds the IDI_ID value directly.
// In this example, I grabbed the IDI_ID value directly.
parItem.itemID = obj[@"IDI"][@"IDI_ID"];
}