RestKit: mapping JSON array of strings

后端 未结 3 1438
甜味超标
甜味超标 2020-12-30 18:14

Given the following JSON:

{
   \"someKey\":\"someValue\",
   \"otherKey\":\"otherValue\",
   \"features\":[
      \"feature1\",
      \"feature2\",
      \"f         


        
3条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-30 18:20

    I don't think you can map an array of strings into a ManagedObject like that. However, since Feature only has one name property you could just store it as an array into your MyTopLevelObject. You can do that by adding a features property to MyTopLevelObject in your datamodel with the type Transformable. RestKit will automatically parse the features a NSArray with NSStrings. You can then get the features as following:

    MyTopLevelObject *topLevelObject = ... // get the object from the persistent store
    NSArray *features = (NSArray*)topLevelObject.features; // this will contain the features as NSString objects
    

提交回复
热议问题