Skip to content

Commit 83a7db9

Browse files
author
姚巍
committed
fix bug
1 parent 52de824 commit 83a7db9

File tree

1 file changed

+22
-7
lines changed

1 file changed

+22
-7
lines changed

JSONConverter/Classes/Builder/JSONBuilder.swift

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -72,13 +72,7 @@ class JSONBuilder {
7272
}
7373

7474
private func addArraryWithParentNodeName(_ parentNodeName: String, keyName: String, valueArrary: [Any]) -> Property? {
75-
var item = valueArrary.first
76-
if valueArrary.first is Dictionary<String, Any> {
77-
var temp = [String: Any]()
78-
valueArrary.forEach { temp.merge($0 as! [String: Any]) { $1 } }
79-
item = temp
80-
}
81-
75+
let item = valueArrary.first is Dictionary<String, Any> ? buildPrefectDictionary(arrary: valueArrary as! [[String : Any]]) : valueArrary.first
8276
if let item = item {
8377
var propertyModel: Property?
8478
switch item {
@@ -103,6 +97,27 @@ class JSONBuilder {
10397
return nil
10498
}
10599
}
100+
101+
private func buildPrefectDictionary(arrary: [[String: Any]]) -> [String: Any] {
102+
var temp = [String: Any]()
103+
arrary.forEach {
104+
temp.merge($0) { (current, new) in
105+
if current is NSNull {
106+
return new
107+
} else if ((current as? NSNumber)?.valueType()) == .Int {
108+
if let newNumType = (new as? NSNumber)?.valueType() {
109+
return (newNumType == .Float || newNumType == .Double) ? new : current
110+
} else {
111+
return new is NSNull ? current : new
112+
}
113+
} else {
114+
return current
115+
}
116+
}
117+
}
118+
119+
return temp
120+
}
106121
}
107122

108123

0 commit comments

Comments
 (0)