Comments (6)
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.
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.
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.
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.
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.
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)
- Gracefully handling JSON's null HOT 1
- Handling dynamic and meaningful keys HOT 5
- Example code issues HOT 1
- Swift 3 support HOT 3
- Array of Dictionary values
- Bool parsing broken on XCode 8.1 HOT 2
- Ambiguous use of 'getString()' HOT 3
- Handling optional array HOT 5
- add name of property in the exception wrongType HOT 2
- 'JSONDecoder' has no member string HOT 2
- Parse String Array Issue HOT 1
- example of Nested Array in object within another object HOT 2
- how to do ? object to jsonstr HOT 1
- Not working with Swift4 HOT 7
- Update to xCode 9 and 'JSONDecoder' is ambiguous for type lookup in this context HOT 2
- Swift 4 issue with HOT 4
- Swift4 compile error HOT 3
- Consider merging with quicktype? HOT 1
- Issue with Swift 4 "JSONLoader' is not a member type of 'JSONJoy"
- Array of Object Not working
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from jsonjoy-swift.