GithubHelp home page GithubHelp logo

Nested JSON about moya-swiftyjsonmapper HOT 4 CLOSED

avdlee avatar avdlee commented on July 20, 2024
Nested JSON

from moya-swiftyjsonmapper.

Comments (4)

AvdLee avatar AvdLee commented on July 20, 2024

You should create a container object for that and map to that container.

self.notifications = try response.map(to: NotificationsList.self)

Inside that container you can map items to your Notification object.

from moya-swiftyjsonmapper.

sandeepbol avatar sandeepbol commented on July 20, 2024

Can you elaborate a little more. You want us to create a container class or struct conforming to Mappable protocol having Notification array as the only member?

from moya-swiftyjsonmapper.

sandeepbol avatar sandeepbol commented on July 20, 2024

Currently, I am manually converting JSON data to inner objects. I don't see it as an efficient method. I mean I am doing something like explained below:

[{
"id": "28266",
"name": "Sandeep",
"coordinates": [{"x": 0, "y": 1},
{...},
{...}]},

{...},
{...}
]

Inside the init?(jsonData: json) of outer model, I am doing for loop for creating inner 'coordinates' array

    if(jsonData["coordinates"] != JSON.null) {
        for json in jsonData["coordinates"].arrayValue {
            coordinatesArray.append(coordinate(jsonData: json)!)
        }
    }

This obviously doesn't seem ideal as I can run a for loop for any level of nesting, then the purpose of a library like this is defied.

Please help me understand how this can be best done? Thanks in advance.

from moya-swiftyjsonmapper.

AvdLee avatar AvdLee commented on July 20, 2024

Closing due to inactivity. Please look up the SwiftJSON documentation for mapping objects if it's still unclear.

from moya-swiftyjsonmapper.

Related Issues (13)

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.