This is My JSON :--
{
"publisherPlans": [
[
"Name",
"Free",
"Prime"
],
[
"Book Sell",
9999,
9999
],
[
"Book Bulk Sell",
0,
9999
],
[
"Magazine start-up",
9999,
9999
],
[
"Demo book request count for School",
5,
9999
],
[
"Demo book request Acception",
9999,
9999
],
[
"Assign book for demo",
25,
9999
],
[
"Upload PDF",
30,
150
],
[
"Upload PDF Size",
300,
1636
],
[
"Upload PDF Pages",
2500,
5000
],
[
"Margin of profits",
70,
100
],
[
"Durability End",
90,
9999
],
[
"Create Story",
5,
10
],
[
"Read Story",
50,
9999
],
[
"Create Stack",
5,
20
],
[
"Read Credit Addition",
9999,
9999
],
[
"Read Credit Withdraw",
0,
9999
]
]
}
This is My Model:--
import Foundation
public struct SchoolPlanModel:Decodable {
public let schoolPlans: SchoolPlans
}
public struct SchoolPlans:Decodable {
public let thead: [[[String]]]
public let tbody: [[[Tbody]]]
}
public enum Tbody: Decodable {
case integer(Int)
case string(String)
}
//This Is View Here I want to show my All Data of API.
struct SchoolPlanView: View{
@StateObject var list = ReadData()
var body: some View{
// ForEach(0..<list.datas.indices){ item in
Text("\(list.datas[0])")
// }
}
}
//This is View Model
class ReadData: ObservableObject {
@Published var datas = [String]()
func getData() async {
guard let url = URL(string: "https://www.alibrary.in/api/alib-plans") else { return }
do {
let (data, _) = try await URLSession.shared.data(from: url)
Task{@MainActor in
let results = try JSONDecoder().decode(SchoolPlanModel.self, from: data).schoolPlans
}
} catch {
print("---> error: \(error)")
}
}
}
And I don't know how can I fetch detail and set to the View?