我正在尝试发送一系列字典,但验证失败。这是一个示例输出:
{
album = "Karaoke - In the style of Goo Goo Dolls - Vol. 2";
artist = "Stingray Music (Karaoke)";
length = "208.404";
title = "Better Days (Karaoke Version)";
},
{
album = Down;
artist = "Jay Sean";
length = "212.61";
title = Down;
},
{
album = "Growing Pains";
artist = "Mary J Blige";
length = "301.844";
title = "Come to Me (Peace)";
}
这是生成它的代码:
NSMutableArray *mutableSongsToSerialize = [NSMutableArray array];
NSArray *songs = [playlist items];
for (MPMediaItem *song in songs){
NSString *title =[song valueForProperty: MPMediaItemPropertyTitle];
NSString *artist =[song valueForProperty: MPMediaItemPropertyAlbumArtist];
NSString *album =[song valueForProperty: MPMediaItemPropertyAlbumTitle];
NSString *length =[song valueForProperty: MPMediaItemPropertyPlaybackDuration];
NSDictionary *songDictionary = @{@"title": title, @"artist": artist, @"album":album, @"length":length};
[mutableSongsToSerialize addObject:songDictionary];
}
NSString *jsonRepresentation = [NSJSONSerialization JSONOBjectWithData:mutableSongsToSerialize options:0 error:NULL];
我认为这条线需要以某种方式进行修改,以便每首歌曲都不会被视为根元素,但我不确定具体要做什么。
NSDictionary *songDictionary = @{@"title": 标题, @"artist": 艺术家, @"album":album, @"length":length};