I am parsing a web api response which is an array of dictionaries. Each dictionary in turn has a nested array of dictionaries. How do i parse it? Pl provide with some code sample.
My api response is,
(
{
FilingStatusId = 0;
FormName = "MISC";
OrderId = 0;
RecipientList = (
{
FilingStatusId = 0;
FormId = 1;
FormName = "MISC";
PayerId = 26142;
PayerName = bsbbshs;
RecipientId = 221438;
RecipientName = tests;
ReturnId = 209998;
UserId = 0;
},
{
FilingStatusId = 0;
FormId = 1;
FormName = "MISC";
PayerId = 26142;
PayerName = bsbbshs;
RecipientId = 221438;
RecipientName = tests;
ReturnId = 209998;
UserId = 0;
}
);
},
{
FilingStatusId = 0;
FormName = "MISC";
OrderId = 0;
RecipientList = (
{
FilingStatusId = 0;
FormId = 1;
FormName = "MISC";
PayerId = 26142;
PayerName = bsbbshs;
RecipientId = 221438;
RecipientName = tests;
ReturnId = 209998;
UserId = 0;
},
{
FilingStatusId = 0;
FormId = 1;
FormName = "MISC";
PayerId = 26142;
PayerName = bsbbshs;
RecipientId = 221438;
RecipientName = tests;
ReturnId = 209998;
UserId = 0;
}
);
}
);
My code so far is,
This is my model for the entire response - ReturnModel
import UIKit
import ObjectMapper
class ReturnModel: Mappable
{
var FilingStatusId : Int = 0
var FormName : String = ""
var OrderId : String = ""
var RecipientList:[[String:Any]] = [[:]]
required init?(map: Map) {
}
func mapping(map: Map)
{
FilingStatusId <- map["FilingStatusId"]
FormName <- map["FormName"]
OrderId <- map["OrderId"]
RecipientList <- map["RecipientList"]
}
}
As of now I am parsing the RecipientList as a dictionary. But I have another Model called RecipientModel. How can I use it inside this ReturnModel to parse the RecipientList ?
Objectmapper handles nested objects as long as they conform to Mappable:
Your first model will represent outer array. And second will represent inner array. Here is a sample
And now you will create another model for your RecipientList