如何在 Objective C 中解析这个 JSON?我一直在使用 jsonmodel.com 的代码来解析。
{
"found":10958,
"start":3141,
"hits":[
{
"pid":"76493",
"title":"Beton Armu00e9",
"artist":"Raiden",
"genre":"Dubstep",
"image":"A76493_BetonArm_BetonArm.jpg",
"label":"Offkey",
"year":"2011",
"price":9.99,
"release":"Beton Armu00e9",
"type":"Album",
"tracks":{
"0":{
"name":"Barbican",
"file":"A76481_Barbican.mp3",
"tracknum":1,
"pid":"76481"
},
"1":{
"name":"Trinity",
"file":"A76482_Trinity.mp3",
"tracknum":2,
"pid":"76482"
},
"2":{
"name":"Tricorn",
"file":"A76483_Tricorn.mp3",
"tracknum":3,
"pid":"76483"
},
"3":{
"name":"Brutalist",
"file":"A76484_Brutalist.mp3",
"tracknum":4,
"pid":"76484"
},
"4":{
"name":"Trellick",
"file":"A76485_Trellick.mp3",
"tracknum":5,
"pid":"76485"
}
}
}
]
}
JSONModel 需要一个指针字符串来声明键,但这里的键是数字。这是我需要的,但不起作用:
#import "JSONModel.h"
#import "songParentModel.h"
@protocol albumModel @end
@interface albumModel : JSONModel
@property (strong,nonatomic) NSString *title;
@property (strong,nonatomic) NSString *image;
@property (strong,nonatomic) NSString *artist;
@property (strong,nonatomic) songParentModel *0; // THIS DOESN'T WORK (of course)
@end
我只需要获得第一首曲目,但知道如何获得所有曲目会很好。
我对解决方案的最佳猜测是停止使用 JSONModel 并使用其他一些简化的方法解析 JSON。