I want to represent any objective-c object in JSON format at RUNTIME, so that a javascript script can use it to access any field/variables/properties through 'dot' notation.
For example,
Objective-c class for the object could be:
@interface myNativeObject
PrimtivieType *pVar;
CustomClassType *cVar;
@end
Where CustomClassType may contain another object as shown below:
@interface CustomDataType
PrimitiveType *myVar;
@end
I want to Expose myNativeObject to JavaScript in JSON format, as follows:
var nativeObjInJavaScript = {
pVar:pval,
cVar:{
myVar:myVarValue
}
}
So, now following JavaScript expression shoule work correctly:
var LValue = nativeObjInJavaScript.cVar.myVar;
I am thinking of
1.) writing a recursive function which will use Objective-C runtime library to get information about the object and generate the JSON equivalent. Am I on the right track?
2.) Key-Value encoding feature of Objective-c could be of any help in this case?
Regards,