Coder Social home page Coder Social logo

Comments (4)

tonyd256 avatar tonyd256 commented on May 24, 2024

If each one of those objects in the array has a model that conforms to JSONDecodable then it's not hard. You can use mapDecode after you get the JSONValue back from JSONValue.parse

from argo.

tonyd256 avatar tonyd256 commented on May 24, 2024

That is if you're using Argo 3.x or 4.x ... If you are on master then it will be different.

from argo.

clayellis avatar clayellis commented on May 24, 2024

@tonyd256 How would you do that today? JSONValue isn't available anymore it seems.

from argo.

gfontenot avatar gfontenot commented on May 24, 2024

Noted this in #17 but I'll drop it in here as well:

JSONValue was renamed JSON at some point (possibly pre-1.0?). The way you'd want to decode an array of objects now is to use the decodeArray helper function:

import Curry // Curry.framework: https://github.com/thoughtbot/Curry
import Argo

struct Foo {
  let id: Int
  let foo: String
}

extension Foo: Decodable {
  static func decode(json: JSON) -> Decoded<Foo> {
    return curry(Foo.init)
      <^> json <| "id"
      <*> json <| "foo"
  }
}

let foos: [Foo]? = decodeArray(json).value

from argo.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.