Giter Site home page Giter Site logo

Comments (6)

rosevinod avatar rosevinod commented on June 8, 2024

as this was not working : decoder.getArray(&scopes) .. i mean how to get all the array back to my view controller: i used instead this to get the array

struct ResponseData : JSONJoy {
var ambulance:[String] = []

init(_ decoder: JSONDecoder) {
    if let addrs = decoder["ambulance"].array {
        for addrDecoder in addrs {
            //print("addrDecoder \(addrDecoder.string!)")
            ambulance.append(addrDecoder.string!)
        }
    }// end if

}// end init decoder

}// end ResponseData

from jsonjoy-swift.

daltoniam avatar daltoniam commented on June 8, 2024

Can you share what your JSON structure looks like? I don't what is wrong in the parsing logic if I don't have the source 😄.

from jsonjoy-swift.

rosevinod avatar rosevinod commented on June 8, 2024

following is the JSON ... let me how to get doctors array out of it.

{
"statusCode": 200,
"status": "success",
"responseData": {
"uri": "http://........./provider_categories/",
"doctor": [
"Ayurveda",
"Cardiologist",
"Dentist",
"Dermatologist",
"Ent",
"Gastroenterologist",
"Gynaecologist",
"Hematologist",
"Homeopathy",
"Neurologist",
"Nutritionist",
"Oncologist",
"Orthopedic",
"Paediatric",
"Physician",
"Physiotherapist",
"Psychiatrist",
"Urologist",
"Veterinary"
],
"pharmacy": [
"24 hrs Pharmacy",
"Ayurvedic Pharmacy"
],
"ambulance": [
"Ambulance Services",
"24 hrs Ambulance Services",
"Air Ambulance",
"Blood Bank",
"24 hrs Blood Bank"
]
}
}

from jsonjoy-swift.

daltoniam avatar daltoniam commented on June 8, 2024
struct ResponseData : JSONJoy {
var doctors:[String] = []
init(_ decoder: JSONDecoder) { 
   if let respData = decoder["responseData"]. dictionary  { //not sure if you are passing the JSON straight in or not, but acc
     respData["doctors"].getArray(&doctors)
   }
}
}

or you can do it the object way:

struct ResponseData : JSONJoy {
var doctors:[String] = []
init(_ decoder: JSONDecoder) { 
   if let respData = decoder["responseData"]. dictionary  { 
     if let docs = decoder["doctors"].array {
            for doc in docs {
                doctors.append(doc.string)
            }
        }
   }
}
}

I just made these off hand, but should give the basic idea.

from jsonjoy-swift.

rosevinod avatar rosevinod commented on June 8, 2024

I got following error for :

-- > Cannot invoke 'getArray' with an argument list of type '(inout [String])'

I don't think : getArray working correctly.. alternative must be use. Please update your document reference to avoid any confusion.

struct ResponseData : JSONJoy {
var doctors:[String] = []
init(_ decoder: JSONDecoder) {
if let respData = decoder["responseData"]. dictionary { //not sure if you are passing the JSON straight in or not, but acc
respData["doctors"].getArray(&doctors)
}
}
}

from jsonjoy-swift.

daltoniam avatar daltoniam commented on June 8, 2024

getArray requires a optional array so it would be var doctors: [String]? in order to work, should have been clearer. I will update the docs to avoid the confusion.

from jsonjoy-swift.

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.