File tree Expand file tree Collapse file tree 1 file changed +22
-7
lines changed
JSONConverter/Classes/Builder Expand file tree Collapse file tree 1 file changed +22
-7
lines changed Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments