ios - JSON 对象映射 - RestKit

标签 ios objective-c iphone json restkit

我有以下 JSON 作为响应。我怎样才能为它做对象映射?我正在使用 iOS - RestKit。

    {  
   "predictions":[  
      {  
         "description":"User1",
         "id":"75b8c57b4443f4b881f0efc94afd52437232aee9"
      },
      {  
         "description":"User2",
         "id":"82aa3303704041cda0e4fc34024d383dbf923604"
      },
      {  
         "description":"User3",
         "id":"f88f669a30934ef599bccf86c0236426cf2d313e"
      },
      {  
         "description":"User4",
         "id":"fa9ae7b65fa52bffdabf00d69e7db5cd37539781"
      },
      {  
         "description":"User5",
         "id":“66df3fd7e400eb31efd3ac935036aab2c02b03f0"
      }
   ],
   "status":"OK"
}

最佳答案

创建一个名为 Prediction 的新类,将 descriptionpredictionId 作为属性,然后使用映射器对象

RKObjectMapping *mapping = [RKObjectMapping mappingForClass:[Prediction class]]; [mapping addAttributeMappingsFromDictionary:@{
@"description":   @"description",
@"id":     @"predictionId",
}];

当然是在你正确解析响应之后

关于ios - JSON 对象映射 - RestKit,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29546245/

相关文章:

ios - 数据未显示在 TableViewController 上

iOS 7 在视频播放中解锁设备方向

iphone - 从网页中读取字符串

iphone - UITableView 带分页上一个,下一个按钮

ios - 在 SceneKit 中,从 scene.rootNode 中删除 SCNNode 节点会导致崩溃

ios - UIBezierPath 用不同的笔画画圆

ios - 使用 UIView 作为 UIButton 的背景?

objective-c - iOS : Trying to add Navigation Bar to Modal UITableViewController

ios - 在 iOS 上高效解析 HealthKit 的 HKSampleQuery 结果

android - Zendesk SDK与API