如何在iOS Swift中基于ID读取本地json文件?

问题描述 投票:0回答:1

我正在离线模式下在ios本机中实现歌曲(仅文本)应用程序。我正在创建本地JSON文件以从这些文件读取数据。我正在使用以下JSON文件,但我不知道这是开发此应用程序的正确格式。但是我想知道当用户单击“下一个和上一个按钮”时如何根据SongID读取特定的歌曲标题和文本。

我的任务:1.需要实现NextSong和PreviousSong按钮2.需要显示歌曲列表的标题

{
  “Telugu_songs“:[
     {
       “Id”: 1,
       “Title”: “song1 title”,
       “Text”: “song1 sample text”
     },
     {
       “Id”: 2,
       “Title”: “song2 title”,
       “Text”: “song2 sample text”
     },
    {
       “Id”: 3,
       “Title”: “song3 title”,
       “Text”: “song3 sample text”
     },
  ],

“English_songs“:[
     {
       “Id”: 1,
       “Title”: “song1 title”,
       “Text”: “song1 sample text”
     },
     {
       “Id”: 2,
       “Title”: “song2 title”,
       “Text”: “song2 sample text”
     },
    {
       “Id”: 3,
       “Title”: “song3 title”,
       “Text”: “song3 sample text”
     },
  ],

“Hindi_songs“:[
     {
       “Id”: 1,
       “Title”: “song1 title”,
       “Text”: “song1 sample text”
     },
     {
       “Id”: 2,
       “Title”: “song2 title”,
       “Text”: “song2 sample text”
     },
    {
       “Id”: 3,
       “Title”: “song3 title”,
       “Text”: “song3 sample text”
     },
  ]
}   

我正在离线模式下在ios本机中实现歌曲(仅文本)应用程序。我正在创建本地JSON文件以从这些文件读取数据。我正在使用以下JSON文件,但我不知道是...

ios json swift swift4.2
1个回答
0
投票

您的JSON格式正确,只是用于包装键和值的双引号似乎是错误的。这是您的工作JSON:

© www.soinside.com 2019 - 2024. All rights reserved.