I'm using JSONModel JSON parser (great library!), and I am getting a problem parsing this JSON response: http://api.setlist.fm/rest/0.1/search/setlists.json?cityName=vilalba The interesting JSON code in the response is the next one:
{
"setlists":{
"@itemsPerPage":"20",
"@page":"1",
"@total":"5",
"setlist":[
{
"@eventDate":"12-04-2014",
"@id":"3bc38430",
"@lastUpdated":"2014-04-13T16:28:36.000+0000",
"@versionId":"53943b55",
"artist":{
"@disambiguation":"",
"@mbid":"8d1e76c8-80b0-44b9-9e86-25d148323a9e",
"@name":"Izal",
"@sortName":"Izal",
"url":"http:\/\/www.setlist.fm\/setlists\/izal-43dc3b23.html"
},
"venue":{
"@id":"73d64e85",
"@name":"Plaza de La Constitución",
"city":{
"@id":"3105522",
"@name":"Vilalba",
"@state":"Galicia",
"@stateCode":"58",
"coords":{
"@lat":"43.3",
"@long":"-7.6833333"
},
"country":{
"@code":"ES",
"@name":"Spain"
}
},
"url":"http:\/\/www.setlist.fm\/venue\/plaza-de-la-constitucion-vilalba-spain-73d64e85.html"
},
"sets":{
"set":{
"song":[
{
"@name":"Despedida"
},
{
"@name":"Hambre"
},
{
"@name":"Jenna Fisher"
},
{
"@name":"La mujer de verde"
}
]
}
},
"url":"http:\/\/www.setlist.fm\/setlist\/izal\/2014\/plaza-de-la-constitucion-vilalba-spain-3bc38430.html"
}
}
}
My model looks this way:
@interface Concert : JSONModel
@property (nonatomic, strong) NSString *concertId;
@property (nonatomic, strong) ConcertArtist *concertArtist;
@property (nonatomic, strong) ConcertPlace *concertPlace;
@property (nonatomic, strong) NSString *concertDate;
@property (nonatomic, strong) NSArray<Optional, ConcertSet> *concertSets;
@property (nonatomic) NSNumber<Ignore> *concertSongsNumber;
@end
@interface ConcertSet : JSONModel
@property (nonatomic, strong) NSDictionary<ConcertSong,Optional> *setSongs;
@property (nonatomic) NSNumber<Optional> *setNumEncore;
@end
Everything goes ok, but when parsing the "sets" JSON code, I am getting the next error:
Invalid JSON data. The JSON type mismatches the expected type. Check the error user information.
kJSONModelTypeMismatch=Property 'concertSets' is declared as NSArray<ConcertSet>* but the corresponding JSON value is not a JSON Array.
kJSONModelKeyPath=concerts.concertSets}
I can't find the error in my code, and I am thinking about Its some kind of JSON data format error. In that case, what would be the possible solution? Thanks in advance! Pablo Blanco
Update: As Ican Zilb said, there is another object between "concert" and "set": "sets". Updating my classes as it follows, parsing goes perfect. Thanks!
@interface Concert : JSONModel
@property (nonatomic, strong) NSString *concertId;
@property (nonatomic, strong) ConcertArtist *concertArtist;
@property (nonatomic, strong) ConcertPlace *concertPlace;
@property (nonatomic, strong) NSString *concertDate;
@property (nonatomic, strong) ConcertSets<Optional> *concertSets;
@property (nonatomic) NSNumber<Ignore> *concertSongsNumber;
@end
@protocol ConcertSets
@end
@interface ConcertSets : JSONModel
@property (nonatomic, strong) NSArray<ConcertSet,Optional> *concertSets;
@end
@protocol ConcertSet
@end
@interface ConcertSet : JSONModel
@property (nonatomic, strong) NSArray<ConcertSong,Optional> *setSongs;
@property (nonatomic) NSNumber<Optional> *setNumEncore;
@end