0

I was wondering if there is any tool which you can paste a JSON (sample web service response) to generate the NSObject data model (create .h .m files as well as defining the properties) automatically.

Let's say you have the following simple JSON:

{
  "firstName": "Alex",
  "lastName": "Morgan"
}

Use the tool to generate person.h & person.m files like this:

@interface Person : NSObject
@property (nonatomic) NSString *firstName;
@property (nonatomic) NSString *lastName;
@end

@implementation Person
@end

Later, just import the files into the project and use them.

Visual Studio has this feature called Paste Special.

rmaddy
  • 314,917
  • 42
  • 532
  • 579
danialmoghaddam
  • 343
  • 1
  • 6
  • 21
  • Possible duplicate of [iOS: Serialize/Deserialize complex JSON generically from NSObject class](http://stackoverflow.com/questions/14958883/ios-serialize-deserialize-complex-json-generically-from-nsobject-class) – ThomasW Nov 12 '15 at 06:53
  • Also see: http://stackoverflow.com/questions/10515015/ios-json-serialization-for-nsobject-based-classes – ThomasW Nov 12 '15 at 06:54
  • @ThomasW The posts don't address the question. I've edited the question more clearly. – danialmoghaddam Nov 12 '15 at 07:13

2 Answers2

3

Give JSONExport a try:

JSONExport is a desktop application for Mac OS X which enables you to export JSON objects as model classes with their associated constructors, utility methods, setters and getters in your favorite language.

tilo
  • 14,009
  • 6
  • 68
  • 85
1

Try these Xcode plugins : ESJsonFormat-Xcode and XWJsonToCode.

You will need to install the Alcatraz plugin first though.

ShahiM
  • 3,179
  • 1
  • 33
  • 58