2014-03-27 84 views

回答

3

幸运的是,Apple提供iOS 5.0的“NSJSONSerialization”类。连载您的数据。 步骤1:将您的本地JSON字符串 “NSData的”

 NSString *strLocalJSON = @"{data= "some data"}"; //just for ex. may not be valid one 
    NSData *dataJSON = [str dataUsingEncoding:NSUTF8StringEncoding]; 

第二步:

id jsonobject= [NSJSONSerialization JSONObjectWithData:dataJSON options:NSJSONReadingMutableContainers error:nil]; // resulting object may contain Dictionary or Array depends on your localjson 

进一步的信息请参考https://developer.apple.com/library/ios/documentation/Foundation/Reference/NSJSONSerialization_Class/Reference/Reference.html

0

如果你的JSON是一个文件,那么你使用file:// NSURL当你创建你的RestKit对象管理器时。其他一切正常。

如果JSON已经在代码中,那么你应该将它保存到一个文件,或者你为什么需要做任何映射?无论如何,你可以使用NSJSONSerializationRKMappingOperation的组合。

相关问题