Giter Site home page Giter Site logo

jsonjoy-swift's People

Contributors

acmacalister avatar asuard avatar biw avatar daltoniam avatar darioalessandro avatar diniska avatar kaunteya avatar kkpoon avatar mpclarkson avatar owenmelbz avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

jsonjoy-swift's Issues

How to parse a string using JSONJoy?

For testing purpose I need to translate a string like "{\"ip\": \"128.74.141.82\"}" to an object, imitating server's response.

How can it be done?

Nested arrays .append

Flowing the instructions I am getting an error about missing the .append function

image

import Cocoa

struct Status_response :JSONJoy {
var status: String?
var issu: Issues?
init(){}
init(_ decoder: JSONDecoder){
status = decoder["status"].string
issu = Issues(decoder["issues"])
}
}

struct Issues:JSONJoy {

var issues: Array<Issue>?
init(){}
init(_ decoder: JSONDecoder){
    //we check if the array is valid then alloc our array and loop through it, creating the new address objects.
    if let issu = decoder["issues"].array {
        issues = Array<Issue>()
        for issuDecoder in issu {
            issues += Issue(issuDecoder)
        }
    }
}

}

struct Issue:JSONJoy {
var id: Int?
var skill_name : String?
var problem : String?
var priority : Int?
init(){}
init(_ decoder: JSONDecoder){
id = decoder["id"].integer
skill_name = decoder["skill_name"].string
problem = decoder["problem"].string
priority = decoder["priority"].integer
}
}

Consider merging with quicktype?

Hi! I am also working on this problem on a project called quicktype and wanted to know if you had any interest in joining forces? Check it out:

We only support Swift 4 Codable at the moment (we had Swift 3 support but removed it). We don't have Objective-C support, but we have a module backend supporting multiple languages, so we can share the frontend and type inference stages. Please check it out and let me know if you're interested!

JSONJoy on real device

Hi, I followed the instructions for allowing build app in a real iphone, but can't do it.
Here is my screen capture
error_xcodejson

Parse String Array Issue

Please provide a sample snippet to parse a array of strings.

Eg.

{
"Places" : [
"Asia",
"Africa",
"America"
]
}

I do not see a straight forward way to parse array of strings like this without a key.Please explain

suggest bool property

It would be nice to have a decoder["…"].bool property:

//convert the value to a bool
public var bool: Bool? {
    if let value = self.value as? String
    {
        return value.lowercaseString == "true"
    }
    return false
}

Array with no Key in JSON

What if you're getting a response of just an array, no keys. for example...

[
    {
        "SecureString" : "this is a string"
    },
    {
        "SecureString" : "this is another string"
    }
]

How can JSONJoy handle that?

'JSONDecoder' has no member string

init(_ decoder: JSONDecoder) {
display_name = decoder["display_name"].string

xcode 8 & swift 3

compiler says 'JSONDecoder' has no member string

how can I fix this?

parsing an array of an array of coordinates

I am trying to figure out how to parse an array of an array of coordinates, and have tried going through the section on arrays in the read me with no luck. Below is the code that I have for a TripInfo object, which works great minus the polyline array.

required public init(_ decoder: JSONDecoder){
        if let hasUserID = decoder["userID"].string{
            userID = hasUserID
        }
        if let hasId = decoder["_id"].string{
            id = hasId
        }
        if let hasPhonePickup = decoder["phonePickupCount"].double{
            phonePickup = hasPhonePickup
        }
        if let hasRapidAccel = decoder["rapidAccelerationCount"].double{
            rapidAccel = hasRapidAccel
        }
        if let hasHardBrake = decoder["hardBrakeCount"].double {
            hardBrake = hasHardBrake
        }
        if let hasAttentionRate = decoder["attentionRate"].double {
            attentionRate = hasAttentionRate
        }
        if let poly = decoder["polyline"].array {
            println("POLY COUNT \(poly.count)")
            var polylines = [AnyObject]()
            for polyDecoder in poly {
                println("POLY DECODER \(Polyline(polyDecoder))")
                polylines.append(Polyline(polyDecoder))
            }
            polyline = polylines
        }
        if let hasScore = decoder["score"].double {
            score = hasScore
        }
        if let hasDistance = decoder["distanceTraveled"].double {
            distance = hasDistance
        }
        if let hasAnswered = decoder["answeredCallCount"].double{
            answeredCallCount = hasAnswered
        }

I have tried creating a Polyline class for the decoder, but I don't feel like it's the correct way to do it:

class Polyline: JSONJoy{

    var coord:[AnyObject]?

    required init(_ decoder: JSONDecoder) {
        coord = decoder.array
    }

}

Here is what the JSON structure is for the polyline that I am wanting to parse:

"polyline": [
                [
                    37.53833374,
                    -122.36442556
                ],
                [
                    37.53860477,
                    -122.36458146
                ],
                [
                    37.53886398,
                    -122.36474189
                ],
                [
                    37.53913555,
                    -122.36490978
                ],
                [
                    37.53940264,
                    -122.36507608
                ],
                [
                    37.53966646,
                    -122.3652386
                ],
                [
                    37.5399271,
                    -122.36539895
                ]
            ],

What is the best way to go about parsing this data?

Example of Nested Array in object

I have an object that contains an array of objects, in this case hosts and consels.

Below is some code, can I get a little assistance as I haven't found an example of this type of usage of JSONJoy

Settings.swift

    let latitude: Double
    let longitude: Double
    var distance: Float
    let black: Int
    let white: Int
    let hosts: Hosts

    init()
    {
        latitude = 0
        longitude = 0
        distance = 0
        black = 0
        white = 0
        hosts = Hosts()
    }

    init(_ decoder: JSONDecoder) {
        latitude = decoder["home_lat"].double!
        longitude = decoder["home_lng"].double!
        distance = decoder["distance"].float!
        black = decoder["black"].integer!
        white = decoder["white"].integer!
    }   

Hosts.swift

import JSONJoy

struct Hosts : JSONJoy {
    var hosts: Array<Host>
    init() {
        hosts = Array<Host>()
    }

    init(_ decoder: JSONDecoder) {
        hosts = Array<Host>()
        //we check if the array is valid then alloc our array and loop through it, creating the new address objects.
        if let conns = decoder.array {
            for hostDecoder in conns {
                hosts.append(Host(hostDecoder))
            }
        }
    }
}

struct Host : JSONJoy {
    var state: String
    var packageDirection: String
    var purpose: String
    var proto: String
    var destinationPort: String?
    var sourcePort: String?
    var classType: String?

    init(_ decoder: JSONDecoder) {
        self.state = decoder["state"].string!
        self.packageDirection = decoder["pack1dir"].string!
        self.purpose = decoder["purpose"].string!
        self.proto = decoder["proto"].string!

        self.destinationPort = decoder["dport"].string
        self.sourcePort = decoder["sport"].string
        self.classType = decoder["class"].string
    }
}

Example JSON:

{
black: 20,
white: 80,
home_lat: 38.167606,
home_lng: -85.304797,
distance: 905,
hosts: [
{
ip: 1236274589,
handle: "1",
quality: 100,
lat: 40,
lng: -85
},
{
ip: 1270515439,
handle: "",
quality: 1,
lat: 39,
lng: -84
},
{
ip: 1676608305,
handle: "",
quality: 2,
lat: 44,
lng: -79
},
{
ip: -822148318,
handle: "",
quality: 1,
lat: 32,
lng: -95
},
{
ip: 1546188984,
handle: "",
quality: 89,
lat: 51,
lng: 0
},
{
ip: 418662793,
handle: "",
quality: 92,
lat: 54,
lng: -128
},
{
ip: 1259536675,
handle: "lumb3r",
quality: 83,
lat: 32,
lng: -97
},
{
ip: 1656966568,
handle: "Vextiles",
quality: 100,
lat: 29,
lng: -95
},
{
ip: 1756634330,
handle: "Legion",
quality: 86,
lat: 38,
lng: -97
},
{
ip: 1817750167,
handle: "JACK",
quality: 0,
lat: 42,
lng: -83
},
{
ip: 850914650,
handle: "matt",
quality: 0,
lat: 38,
lng: -105
},
{
ip: 1287191577,
handle: "beyondr",
quality: 0,
lat: 33,
lng: -97
},
{
ip: 1808987642,
handle: "graveyard",
quality: 0,
lat: 30,
lng: -90
},
{
ip: 1678277474,
handle: "jimmy",
quality: 0,
lat: 38,
lng: -97
},
{
ip: 1678273633,
handle: "etheric",
quality: 0,
lat: 38,
lng: -97
},
{
ip: 1247978822,
handle: "Freytos",
quality: 0,
lat: 36,
lng: -76
},
{
ip: 1633640910,
handle: "iBgoods",
quality: 0,
lat: 43,
lng: -85
},
{
ip: 844984152,
handle: "phantom",
quality: 0,
lat: 43,
lng: -79
},
{
ip: 1269746077,
handle: "captin malboro",
quality: 100,
lat: 33,
lng: -112
}
],
consel: [
{
enabled: false,
connections: [
{
state: "NEW",
pack1dir: "in",
purpose: "g",
dport: "1024:65535",
proto: "udp"
},
{
state: "NEW",
proto: "udp",
purpose: "g",
sport: "1024:65535",
pack1dir: "in"
},
{
pack1dir: "either",
purpose: "g",
class: "0",
proto: "udp",
dport: "1024:65535"
},
{
pack1dir: "either",
purpose: "g",
class: "0",
sport: "1024:65535",
proto: "udp"
}
],
name: "Xbox live",
id: 1,
mac: "50:1A:C5:89:12:FB"
},
{
enabled: false,
connections: [
{
state: "NEW",
proto: "udp",
purpose: "g",
sport: "10000:65535",
pack1dir: "either"
}
],
name: "Wii Online",
id: 2,
mac: "80:19:34:71:0D:31"
}
],
strict_mode: true,
pingass: 22
}

JSONJoy-Swift version prior to 7.0

Hi daltoniam, you specified that your library works in iOS 7.0, but it is specified as 8.0 minimum requirement in cocoapod. Is there limitation in 7.0 ?

Swift 4 issue with

In below two functions

/**
get typed Array of JSONJoy and have it throw if it doesn't work
*/
public func get<T: JSONJoy>() throws -> [T] {
guard let a = getOptionalArray() else { throw JSONError.wrongType }
return try a.reduce(T) { $0.0 + [try T($0.1)] }
}

/**
 get typed `Array` and have it throw if it doesn't work
 */
open func get<T: JSONBasicType>() throws -> [T] {
    guard let a = getOptionalArray() else { throw JSONError.wrongType }
    return try a.reduce([T]()) { $0.0 + [try $0.1.get()] }
}

In below two return values

return try a.reduce(T) { $0.0 + [try T($0.1)] }
return try a.reduce(T) { $0.0 + [try $0.1.get()] }

Error = "Contextual type for closure argument list expects 1 argument, but 2 were specified".

Update your code respectively.

Error: Use a module 'JSONJoy' as a type

Got this error with my code, i imported JSONJoy.xcodeproj and added to Build Phrase

struct Article : JSONJoy {
  var id: String?
  var date: NSDate?
  var title: String?
  var body: String?

  init() {

  }
}

CMD + Left Click "import JSONJoy"

import Foundation
import JSONJoy
import UIKit

//
//  JSONJoy.h
//  JSONJoy
//
//  Created by Austin Cherry on 9/24/14.
//  Copyright (c) 2014 Vluxe. All rights reserved.
//

//! Project version number for JSONJoy.
var JSONJoyVersionNumber: Double

seems no any class or prototype in framework.

Gracefully handling JSON's null

I'm reading JSON from a server. A key in the decoder has a possibility to be either an integer or a JSON null. I'd like for it to easily be turned into a Swift Int?. Here's how I handle that, in an extension:

public func getIntOptional() throws -> Int? {
    if isNull() {return nil}
    guard let i = integer else {throw JSONError.WrongType}
    return i
}

public func isNull() -> Bool {
    if let raw = rawValue {
        if let rawNS = raw as? NSObject {
            if rawNS == NSNull() {
                return true
            }
        }
    }
    return false
}

This seems kind of clumsy, especially the forced unwrapping and casting. Is there a better way?

Some User model, different JSON keys?

I am using JSONJoy and SwiftHTTP, both are awesome, thanks!

Everything works great when using SwiftHTTP to create a local account (ie not using FB). However when using facebook login, the JSON object returns slightly different keys

For example, our local API returns firstName : Travis FB returns first_name : Travis

I would like to use the same User model if possible and was wondering if there is a way I can assign firstName to either decoder["firstName"].string or decoder["first_name"].string depending on if I sent the local User object or the FB user object.

Cheers,
-Travis

Bool parsing broken on XCode 8.1

"open var bool: Bool" is broken on XCode 8.1

The underlying json parsing library is now returning the Bool type when parsing my server bool responses. Simple fix, I made this small change locally as a workaround:

///treat the value as a bool
open var bool: Bool {
    if let val = self.value as? Bool {
        return val
    } else if let str = self.string {
        let lower = str.lowercased()
        if lower == "true" || Int(lower) > 0 {
            return true
        }
    } else if let num = self.integer {
        return num > 0
    } else if let num = self.double {
        return num > 0.99
    } else if let num = self.float {
        return num > 0.99
    }
    return false
}

Question?

Hi, I have the following JSONDecoder:
Optional({
AppUserId = "JSONJoy.JSONDecoder";
ContentToDisplay = "JSONJoy.JSONDecoder";
CreationDate = "JSONJoy.JSONDecoder";
ExiprationDate = "JSONJoy.JSONDecoder";
IsSeenByUser = "JSONJoy.JSONDecoder";
NotificationContent = "JSONJoy.JSONDecoder";
NotificationID = "JSONJoy.JSONDecoder";
NotificationType = "JSONJoy.JSONDecoder";
SISUserID = "JSONJoy.JSONDecoder";
SISUserNumber = "JSONJoy.JSONDecoder";
})

All keys return a value except for "NotificationContent" it returns another JSON. I was able to get all values by using: decoder["AppUserID"] for example, but for NotificationContent I had to read it as String, convert it to NSData then decode it using JSONDecoder, using decoder["NotificationContent"] just didn't work. Below is my full code, it would be great if you let me know what I'm doing wrong

 let resultDecoder = JSONDecoder(response)[resultKey];
        let serverResponse = ServerResponseModel(resultDecoder);
        if serverResponse.Result == 0 {
            var resultArray: Array<JSONDecoder>? = resultDecoder["OperationData"].array;
            if let arr = resultArray {
                for i in arr {
                    let jsonNotificationType = i["NotificationType"].integer!;
                    let jsonMessage: JSONDecoder = i["NotificationContent"]; // This did not work, it was treated like i["NotificationContent"] value was sent as a String and not NSData (if you recall my last issue I provided it's link below the code) 
                    // For some reason we must decode NotificationContenet again like shown below
                    let x = (i["NotificationContent"].string! as NSString).dataUsingEncoding(NSUTF8StringEncoding);
                    switch jsonNotificationType{
                    case 0:
                        let messageModel = MessageModel(JSONDecoder(x!));
                    break;
                 }
               }

Link to my previous issue in-case it can help

json parse array?

can you help me please?
In README.md, Array and Dictionary support. I use second option to embed objects but at
for address in decoder["addresses"].array ... it get error "Could not find member 'array' ".

How to fix it? (with xcode 6)

JSONDecoder.description not json valid

In case of a NSNull object value, description call returns instead of null.
For example it returns
{ "test": }
instead of
{ "test": null }

With this problem, it's not possible to create a new JSONDecoder from the description:
let desc = jsonDecoder1.description
let nsData = (desc as NSString).dataUsingEncoding(NSUTF8StringEncoding)
let jsonDecoder2 = JSONDecoder(nsData!)
jsonDecoder2 is failed if there is a null value...

import JSONJoy with CocoaPods 0.36.0.beta.1

Using CocoaPods 0.36.0.beta.1 the:

import JSONJoy

needs to be replaced with:

import JSONJoy_Swift

Probably the new module_name attribute in Podspec can help fixing this.

Debug

Is there any way to print/debug json payload? It would be nice to have such functionality in JSONDecoder

add name of property in the exception wrongType

It would be very nice to have name of property when exception wrongType is fired
else debugging of model would be a pain

also ideally would say something like (exception wrongType for field 'address', 'string' expected', 'int' provided

Handling optional array

Hi Dalton,

This is a great tool. Thanks.

I encountered a scenario.

String? can use getOptional() to obtain string
[String]? will result in nil

How to resolve? Or did I miss something.

Ambiguous use of 'getString()'

Hi,

with version 2.1.0 I am unable to use the framework as for example

jsonDecoder["MyKey"].getString()

fails, as there is one getString() that throws and one that returns an optional.

EDIT: This is also true for getInt() etc.

Best regards

Best metaphor ever...

Super subtle nerdity with the Gandalf's eagles to Mordor theory. Worthy of opening an issue.

Wish there was a complete example of tying it all together...

Here's what my response handler from swift looks like, my response object is nested in a "data" attribute While I've been able to figure out how to parse arrays, how do I do this for a rather simple object?

 var jDecoder = JSONDecoder(response.responseObject!)["data"]
 var p =  Profile( jDecoder )

all my values in my struct are nil? How do I create a decoder with nested property on my response?

Using JSONJoy with Realm

Hi, I'd like to use Realm together with JSONJoy.

I don't want to create separate objects for both the libraries. Is it possible somehow to use 1 object for both libs? Since Realm objects are classes that inherit from OBJECT.

class Dog: Object {
  dynamic var name = ""
  dynamic var age = 0
}

Do you have tips and solutions on this? :)

Impossible to extend

Hi!
I've used your library via CocoaPods and faced a problem with adding of new types via extension mechanism: since variable "value" is not public, it is impossible to write an extension(for example, for UInt64 support):

public extension JSONDecoder {
    public var unsignedLong: UInt64? {
        return (value as? NSNumber)?.unsignedLongLongValue
    }
}

because "value" is an internal field of the JSONDecoder class and is available only inside it's module.

Handling dynamic and meaningful keys

Hi Dalton, library is a life-saver, thank you thank you.

Question: I have JSON that looks like this:

{
    "userdata": {
        "192.168.88.253": {
            "applications": {
                "54.230.87.156": {
                    "upbytes": 1055296,
                    "downbytes": 297264
                },
                "63.203.87.82": {
                    "upbytes": 18816,
                    "downbytes": 18816
                },
                "63.203.87.92": {
                    "upbytes": 18816,
                    "downbytes": 18816
                }
            }
        }
    }
}

Before I go and refactor this to be an array.. Is there a way JSONJoy can decode dynamic and meaningful keys like this?

In the above example '192.168.88.253' is a key I can't get to decode since it can be any arbitrary IP address (and there may be 0-infinity passed to JSONJoy).

My code needs access to both the IP, its applications and then for each application another dynamic and meaningful key and then its bytes data.

I could convert these down to just arrays of arrays without meaningful keys but that will create a domino effect of refactoring I'd like to avoid..

Thanks!

example of Nested Array in object within another object

@daltoniam could you please help me out

  {
 "statusCode": 200,
 "statusMessage": "Success",
 "data": {
 "TotalCount": 3,
"GetHomeHistory": [
   {
   "GroupType": "3",
   "GroupName": "name2",
   "MessageId": 1829,
   "ConversationId": 46,
   "DeliveryTimeStamp": "4/6/2017 4:38:12 AM",
   "MessageTranscationId": "3049",
   "MessageText": "SGVsbG8=",
   "Unread_Message_Count": 24,
   "UserId": 69
 },
 {
   "GroupType": "2",
   "GroupName": "name2,name1",
   "MessageId": 1754,
   "ConversationId": 47,
   "DeliveryTimeStamp": "3/4/2017 7:01:17 AM",
   "MessageTranscationId": "2932",
   "MessageText": "UnRncg==",
   "Unread_Message_Count": 4,
   "UserId": 69
 },
 {
   "GroupType": "1",
   "GroupName": "name3",
   "MessageId": 1753,
   "ConversationId": 49,
   "DeliveryTimeStamp": "2/28/2017 10:23:24 AM",
   "MessageTranscationId": "2931",
   "MessageText": "UnRncg==",
   "Unread_Message_Count": 1,
   "UserId": 69
 }
 ]
}
} 

how to extract the key value of "GetHomeHistory" which is an array of objects

I am doing in the following way

  struct HomeModel : JSONJoy {
  let status:Int
  let message:String
  let totalCount: Int
  var conversationHistoryArr: [ConversationHistoryModel]? =  [ConversationHistoryModel] ()
  init(_ decoder: JSONDecoder) throws {

status = try decoder["statusCode"].getInt()
message = try decoder["statusMessage"].getString()
if let respData = decoder["data"].dictionary  {
    if respData["TotalCount"]?.getInt() != nil {
        totalCount = (respData["TotalCount"]?.getInt())!
    } else {
        totalCount = 0
    }
    if respData["GetHomeHistory"]?.getArray(&conversationHistoryArr) != nil{

        if let homeHistoryData = decoder["GetHomeHistory"].array{
            for rsp in homeHistoryData {
                let resp = try?  ConversationHistoryModel(rsp)
                print(resp as Any)
                conversationHistoryArr?.append(resp!)
            }
        }
        else{
            conversationHistoryArr = [ConversationHistoryModel]()
        }

    }


}
else{
    totalCount = 0
 }
 }
 }

my "ConversationHistoryModel" is as follows

 struct ConversationHistoryModel : JSONJoy {
 let groupType:String
 let groupName:String
 let messageId:Int
 let conversationId:Int
  let messageTime:String
 let messageTransactionId:String
 let messageText:String
 let unreadMessageCount:Int
 let userId:Int

 init(_ respData: JSONDecoder) throws {
 if respData["GroupType"].getString() != nil{
    groupType = (respData["GroupType"].getString())!
}
else{
    groupType = ""
}
if respData["GroupName"].getString() != nil {
    groupName = (respData["GroupName"].getString())!
} else {
    groupName = ""
}
if respData["MessageId"].getInt() != nil {
    messageId = (respData["MessageId"].getInt())!
} else {
    messageId = 0
}
if respData["ConversationId"].getInt() != nil {
    conversationId = (respData["ConversationId"].getInt())!
} else {
    conversationId = 0
}
if respData["DeliveryTimeStamp"].getString() != nil {
    messageTime = (respData["DeliveryTimeStamp"].getString())!
} else {
    messageTime = ""
}
if respData["MessageTranscationId"].getString() != nil {
    messageTransactionId = (respData["MessageTranscationId"].getString())!
} else {
    messageTransactionId = ""
}
if respData["MessageText"].getString() != nil {
    messageText = (respData["MessageText"].getString())!
} else {
    messageText = ""
}
if respData["Unread_Message_Count"].getInt() != nil {
    unreadMessageCount = (respData["Unread_Message_Count"].getInt())!
} else {
    unreadMessageCount = 0
}

if respData["UserId"].getInt() != nil {
    userId = (respData["UserId"].getInt())!
} else {
    userId = 0
}
}
}

Any help is appreciated

Parse JSON from WCF?

Hi, I'm using SwiftHTTP to get a JSON response from a WCF REST Service, the json response is as follows:

"{"LoginResult":{"AppUserInformation":{"FirstName":"omar","LastName":"bizreh","UserID":"d157d366-fec8-4d9e-a71e-12539d5e47df","Email":"[email protected]"},"ChildrenAccounts":[{"FullName":"Ahmad Bizreh","PersonID":"b6bc1eba-2dff-437c-bb98-56d0aa768b87","SISNumber":"7001-500111"},{"FullName":"Shadi Bizreh","PersonID":"4c26c2a6-1e81-417f-9f62-b77350ebf387","SISNumber":"7001-500112"},{"FullName":"Rami Bizreh","PersonID":"0aeb1d2f-a6d8-4ecc-a139-fe64afb19617","SISNumber":"7001-500121"}],"Result":0,"SISUserInformation":[{"FirstName":"Omar","LastName":"Bizreh","UserID":"87b145a6-72a2-4a02-adf0-df841dc9a3d1","AccountType":"fe19da29-2ee3-439d-b2b3-edab755fce0b","Password":"123456","SISUserNumber":"7001-5001","SchoolID":"d9cd4a51-91ce-4734-a048-4392921354db","Username":"7001-50011"},{"FirstName":"Omar","LastName":"Bizreh","UserID":"b3a670ac-cee0-422f-9f80-6d62e3643820","AccountType":"fe19da29-2ee3-439d-b2b3-edab755fce0b","Password":"123456","SISUserNumber":"7001-50012","SchoolID":"d9cd4a51-91ce-4734-a048-4392921354db","Username":"7001-50012"}]}}"

As you can see the json that matches your example in the readme, is presented as value for key LoginResult, how do I parse this with JSONJoy?
The response is formatted as follows:
LoginResult:

  1. AppUserInformation (Serialized by .Net from a class)
  2. ChildrenAccounts (Serialized by .Net from an array of class)
  3. SisUserInformation (Serialized by .Net from an array of class)

In your samples I understood how to parse the response if it wasn't presented as value for a key (in my case LoginResult).

Any help would be great.

Thank you.

Swift4 compile error

First of all, thank for your development.

My swift project made in swift 4 version, and JSONJoy 3.0.2 version.

I'm stuck in the error msg when complie. That msg was "Contextual closure type '(_, _) -> _' expects 2 arguments, but 1 was used in closure body"..

so i can't modify ..

the code is

public func getOptional<T: JSONJoy>() -> [T]? {
guard let a = getOptionalArray() else { return nil }
do { return try a.reduce(T) { $0.0 + [try T($0.1)] } }
catch { return nil }
}

Example code issues

Hi there!

While trying out this amazing tool I noticed two small, and easy to fix issue:

  • missing , character in addresses JSON array after id (both in user and array example)
  • postal code is defined as String on swift, but represented as number in JSON

Should I create a pr or will you handle this?

version mismatch in README

Gives this error when trying to follow the instructions in README.

[!] Unable to satisfy the following requirements:

- `JSONJoy-Swift (~> 1.1.0)` required by `Podfile`

The latest release is 1.0.1 and using this version number in podfile solves the issue.

Want to use it on watchos 2

Hi, I want to use it on watch os, how its possible?

now i got Target 'JSONJoy-Swift' of project 'Pods' was rejected as an implicit dependency for 'JSONJoy.framework' because it doesn't contain platform 'watchsimulator' in its SUPPORTED_PLATFORMS 'iphonesimulator, iphoneos'

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.