Skip to content
This repository was archived by the owner on Mar 23, 2021. It is now read-only.
This repository was archived by the owner on Mar 23, 2021. It is now read-only.

dataFromJson() Int 0,1 exchange Bool #57

@iq3addLi

Description

@iq3addLi

Use Vapor 1.0.3 contains Jay. Xcode 8.0.

.Package(url: "https://github.com/DanToml/Jay.git", majorVersion: 1)

func dictionaryToJayType(_ maybeDictionary: Any) throws -> JSON? {

    let mirror = Mirror(reflecting: maybeDictionary)
    let childrenValues = mirror.children.map { $0.value }

    var obj = [String: JSON]()
    for i in childrenValues {

        let childMirror = Mirror(reflecting: i)
        let children = childMirror.children
        if childMirror.displayStyle == .tuple && children.count == 2 {
            let it = children.makeIterator()
            let maybeKey = it.next()!.value
            guard let key = maybeKey as? String else {
                throw JayError.keyIsNotString(maybeKey)
            }
            let value = it.next()!.value
            obj[key] = try self.toJayType(value) // Int 1 -> .boolean(true)
        } else {
            throw JayError.unsupportedType(childMirror)
        }
    }
    return .object(obj)
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions