JSON 对象映射 - RestKit

JSON Object Mapping - 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 的新 class,将 descriptionpredictionId 作为属性,然后使用映射器对象

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

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