'Unable to use Financial Modeling API for swiftui project

For the past couple of days, I have been trying to access stock news stories from the FMP API for a swift project. The data comes as a JSON in this response form:

struct ResponseBody: Decodable{
    var image: String
    var publishedDate: String
    var site: String
    var symbol: String
    var text: String
    var title: String
    var url: String
}

or

[ {
  "symbol" : "BAM",
  "publishedDate" : "2022-02-20 20:02:00",
  "title" : "Australia's AGL Energy rejects $3.5 billion offer, backs decision to split",
  "image" : "https://cdn.snapi.dev/images/v1/m/0/m02d20220221t2i1591787921w940fhfwllplsqrlynxmpei1k013-1242500.jpg",
  "site" : "Reuters",
  "text" : "(Reuters) -Australian power producer AGL Energy Ltd on Monday rejected a $3.54 billion takeover offer from billionaire Mike Cannon-Brookes and Canada's Brookfield Asset Management in favour of its plan of splitting in two this year.",
  "url" : "https://www.reuters.com/business/energy/agl-rejects-35-bln-bid-australias-second-richest-man-brookfield-2022-02-20/"
}, {
  "symbol" : "UBER",
  "publishedDate" : "2022-02-20 19:52:35",
  "title" : "Uber In Portugal Is Now Offering Home Healthcare Visits",
  "image" : "https://cdn.snapi.dev/images/v1/v/s/uber-in-portugal-is-now-offering-home-healthcare-visits-1242497.jpg",
  "site" : "Forbes",
  "text" : "Uber boldly continues to expand its presence in healthcare.",
  "url" : "https://www.forbes.com/sites/saibala/2022/02/20/uber-in-portugal-is-now-offering-home-healthcare-visits/"
}, 
etc.

I am very new to SwiftUI, and I have looked all over for answers but none have worked. My goal is to take the 5 most recent news stories and use the data above to make it fit into a struct I already made that looks like this:

struct SingularStory: View {
    var story: ResponseBody = previewNews
    
    var body: some View {
        VStack(alignment: .leading, spacing: 4) {
            HStack {
                VStack {
                    
                    VStack(alignment: .leading, spacing: 8){
                        
                        
                        Text(story.site)
                        Text(story.title)
                            .bold()
                            .font(.subheadline)
                        
                        HStack {
                            Text(story.publishedDate)
                            Image("Rectangle 37")
                            Text(story.symbol)
                        }
                        
                    }
                    
                }
                Spacer()
                
                
                
                AsyncImage(url: URL(string: previewNews.image)) { image in
                    image
                        .resizable()
                        .scaledToFill()
                } placeholder: {
                    ProgressView()
                }
                .frame(width: 64, height: 64)
                .aspectRatio(contentMode: .fill)
                .cornerRadius(6)
                .padding(.trailing, 24)
                
                
            }
            .padding(.leading)
            
            Bar()
                .padding(.vertical, 20)
        }
    }
}

Any ideas for being able to fetch the data from the site, convert the JSON data into a form suitable for placement in SingularStory, and then presenting 5 of those stories would be greatly appreciated.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source