plist - ios如何获取两层数组里面的内容,数组为字典类型!?
PHPz
PHPz 2017-04-17 16:27:42
0
2
680

ios中的plist文件为数组里面为字典数组包含四个元素,字典又包括两个属性 如下图分别为NSString 和NSArray,第二层array下面依然是一个字典数组,每个字典包含对应的属性,现已经将数据显示到一个tableView里面,如下图

现在想获得数组musics里面的值,包括歌曲名和歌手名以及歌曲的链接,请问该如何获取到数据

PHPz
PHPz

学习是最好的投资!

reply all(2)
Ty80

In fact, this kind of problem belongs to the problem of peeling garlic. . It peeled off with some patience.
The whole thing is an array, right?


  items = [@item0,@teim1,@item2, @item3];
  
Look at the attributes of item0 and continue peeling the garlic

  NSDictionary *item = items[0];
Look at the attributes of music under item0 and continue peeling the garlic

 NSArray *musics = item[@"musics"]
 
Then continue to peel the garlic.... For this type of question, just peel the garlic based on the attributes,

But I generally don’t recommend this method of playing, it is not intuitive and easy to make mistakes. Modify the data structure and the whole person will be sb. Peel the garlic again.

So you can take a look at JSONModel. If you don’t understand it very well, you can also ask me.

https://github.com/icanzilb/JSONModel
A project to model data, similar to GSON in Java. Although the efficiency is average, it is very easy to use, much easier to use than those with high efficiency.

大家讲道理

Get the array with key=music in item0
Then get the dictionary based on index from this array
Then get it from the dictionary based on key

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!