Skip to content

Commit

Permalink
fix bug
Browse files Browse the repository at this point in the history
  • Loading branch information
姚巍 committed Nov 30, 2021
1 parent 52de824 commit 83a7db9
Showing 1 changed file with 22 additions and 7 deletions.
29 changes: 22 additions & 7 deletions JSONConverter/Classes/Builder/JSONBuilder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,7 @@ class JSONBuilder {
}

private func addArraryWithParentNodeName(_ parentNodeName: String, keyName: String, valueArrary: [Any]) -> Property? {
var item = valueArrary.first
if valueArrary.first is Dictionary<String, Any> {
var temp = [String: Any]()
valueArrary.forEach { temp.merge($0 as! [String: Any]) { $1 } }
item = temp
}

let item = valueArrary.first is Dictionary<String, Any> ? buildPrefectDictionary(arrary: valueArrary as! [[String : Any]]) : valueArrary.first
if let item = item {
var propertyModel: Property?
switch item {
Expand All @@ -103,6 +97,27 @@ class JSONBuilder {
return nil
}
}

private func buildPrefectDictionary(arrary: [[String: Any]]) -> [String: Any] {
var temp = [String: Any]()
arrary.forEach {
temp.merge($0) { (current, new) in
if current is NSNull {
return new
} else if ((current as? NSNumber)?.valueType()) == .Int {
if let newNumType = (new as? NSNumber)?.valueType() {
return (newNumType == .Float || newNumType == .Double) ? new : current
} else {
return new is NSNull ? current : new
}
} else {
return current
}
}
}

return temp
}
}


Expand Down

0 comments on commit 83a7db9

Please sign in to comment.