iOS
iOS

Reputation: 3616

JSON Object Mapping - RestKit

I have the below JSON as response. How can I do object mapping for it? I am using 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"
}

Upvotes: 0

Views: 109

Answers (1)

M_Waly
M_Waly

Reputation: 241

Create a new class called Prediction with description and predictionId as properties and then use the mapper object

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

of course after you parse the response correctly

Upvotes: 1

Related Questions