I have a complex object that contains ivars of type NSString, NSArray, BOOL etc. I need to convert them to JSON.
What I am currently doing is setting the Keys for each of the NSObject's values (although the keys are same as the NSObject's properties) like below :-
[crEntityDict setObject:[[MyObjectName sharedObject] vinNumber] forKey:@"vinNumber"];
[crEntityDict setObject:[[MyObjectName sharedObject] make] forKey:@"make"];
MyObjectName is a Singleton object having the same properties as the keys set here. I just could not find how to convert this object directly into an NSDictionary with properties' names as Keys and properties' values as Values.
Is there any better, simpler way to do this?
EDIT Here is the complete Header file code for the NSObject that I am trying to convert to JSON :- MyObjectName.h
#import <Foundation/Foundation.h>
@interface MyObjectName : NSObject
{
NSString *vinNumber,*make,*model;
int mileage;
BOOL isKeyPresent;
}
@property (nonatomic,strong) NSString *vinNumber,*make,*model;
@property (nonatomic,assign) int mileage;
@property (nonatomic,assign) BOOL isKeyPresent;
+ (MyObjectName *)sharedObjectName;
How can I directly convert this Object to a JSON representation, without creating a NSDictionary again by setting the values for the keys with same names as ivars, with the property names as Keys and property values as Values like : {"vinNumber":,"make":make_value_string,"model":model_value_string,"mileage":mileage_value_int,"isKeyPresent":isKeyPresent_value_bool}