Pircate / CleanJSON

Swift JSON decoder for Codable
MIT License
292 stars 40 forks source link

decode结构体走了message send,导致crash #16

Closed RhettTamp closed 3 years ago

RhettTamp commented 3 years ago

FATAL_SIGNAL SIGABRT fault_address:0x00000001ef024dd0 Thread 0 name: com.apple.main-thread 0libsystem_kernel.dylib _abort_with_payload (in libsystem_kernel.dylib) 1libsystem_kernel.dylib _abort_with_payload_wrapper_internal (in libsystem_kernel.dylib) 2libsystem_kernel.dylib _abort_with_payload_wrapper_internal (in libsystem_kernel.dylib) 3libobjc.A.dylib _objcfatalv(unsigned long long, unsigned long long, char const, char) (in libobjc.A.dylib) 4libobjc.A.dylib objc_error (in libobjc.A.dylib) 5libobjc.A.dylib _lookUpImpOrForward (in libobjc.A.dylib) 6libobjc.A.dylib __objc_msgSend_uncached (in libobjc.A.dylib) 7libswiftCore.dylib _swift_instantiateObjCClass (in libswiftCore.dylib) 8libswiftCore.dylib _swift_initClassMetadataImpl(swift::TargetClassMetadata, swift::ClassLayoutFlags, unsigned long, swift::TypeLayout const const, unsigned long, bool) (in libswiftCore.dylib) 9libswiftCore.dylib type metadata completion function for _KeyedDecodingContainerBox (in libswiftCore.dylib) 10libswiftCore.dylib swift::MetadataCacheEntryBase<(anonymous namespace)::GenericCacheEntry, void const>::doInitialization(swift::ConcurrencyControl&, swift::MetadataCompletionQueueEntry, swift::MetadataRequest) (in libswiftCore.dylib) 11libswiftCore.dylib _swift_getGenericMetadata (in libswiftCore.dylib) 12libswiftCore.dylib KeyedDecodingContainer.init(A1) (in libswiftCore.dylib) 1 MyProj _CleanJSONDecoder.container(keyedBy: A.Type) (in MyProj) _CleanJSONDecoder.swift:75 1 MyProj protocol witness for Decoder.container(keyedBy: A1.Type) in conformance _CleanJSONDecoder (in MyProj) :0 15libswiftCore.dylib dispatch thunk of Decoder.container(keyedBy: A1.Type) (in libswiftCore.dylib) 1 MyProj specialized GradeTab.init(from: Decoder) (in MyProj) :0 1 MyProj protocol witness for Decodable.init(from: Decoder) in conformance GradeTab (in MyProj) :0 18libswiftCore.dylib dispatch thunk of Decodable.init(from: Decoder) (in libswiftCore.dylib) 1 MyProj CleanJSONDecoder.unbox(_: Any, as: Decodable.Type) (in MyProj) _CleanJSONDecoder+Unbox.swift:475 2 MyProj CleanJSONDecoder.unbox(: Any, as: A.Type) (in MyProj) _CleanJSONDecoder+Unbox.swift:454 2 MyProj CleanJSONUnkeyedDecodingContainer.decode(A.Type) (in MyProj) CleanJSONUnkeyedDecodingContainer.swift:411 2 MyProj protocol witness for UnkeyedDecodingContainer.decode(A1.Type) in conformance CleanJSONUnkeyedDecodingContainer (in MyProj) :0 23libswiftCore.dylib Array.init(from: Decoder) (in libswiftCore.dylib) 24libswiftCore.dylib protocol witness for Decodable.init(from: Decoder) in conformance [A] (in libswiftCore.dylib) 25libswiftCore.dylib protocol witness for Decodable.init(from: Decoder) in conformance [A] (in libswiftCore.dylib) 26libswiftCore.dylib dispatch thunk of Decodable.init(from: Decoder) (in libswiftCore.dylib) 2 MyProj CleanJSONDecoder.unbox(_: Any, as: Decodable.Type) (in MyProj) _CleanJSONDecoder+Unbox.swift:475 2 MyProj CleanJSONDecoder.unbox(: Any, as: A.Type) (in MyProj) _CleanJSONDecoder+Unbox.swift:454 2 MyProj decodeObject #1 (from: CleanJSONDecoder) in CleanJSONKeyedDecodingContainer.decodeIfPresent(: A1.Type, forKey: A) (in MyProj) CleanJSONKeyedDecodingContainer.swift:886 3 MyProj protocol witness for KeyedDecodingContainerProtocol.decodeIfPresent(_: A1.Type, forKey: A.Key) in conformance CleanJSONKeyedDecodingContainer (in MyProj) :870 31libswiftCore.dylib KeyedDecodingContainerBox.decodeIfPresent(: A1.Type, forKey: A.Key) (in libswiftCore.dylib) 32libswiftCore.dylib KeyedDecodingContainer.decodeIfPresent(_: A1.Type, forKey: A) (in libswiftCore.dylib) 3 MyProj specialized PARespCourseSelectTabsConfigModel.init(from: Decoder) (in MyProj) :0 3 MyProj protocol witness for Decodable.init(from: Decoder) in conformance PARespCourseSelectTabsConfigModel (in MyProj) :0 35libswiftCore.dylib dispatch thunk of Decodable.init(from: Decoder) (in libswiftCore.dylib) 3 MyProj CleanJSONDecoder.unbox(_: Any, as: Decodable.Type) (in MyProj) _CleanJSONDecoder+Unbox.swift:475 3 MyProj CleanJSONDecoder.unbox(: Any, as: A.Type) (in MyProj) CleanJSONDecoder+Unbox.swift:454 3 MyProj CleanJSONDecoder.decode(: A.Type, from: Any) (in MyProj) CleanJSONDecoder.swift:113 3 MyProj CleanJSONDecoder.decode(: A.Type, from: JSONContainerConvertible) (in MyProj) CleanJSONDecoder.swift:101 4 MyProj xxxStruct.transModel(: A.Type, withKeyValues: [String : Any]) (in MyProj) xxx.swift:208

Pircate commented 3 years ago

可以提供一下你的结构体吗

RhettTamp commented 3 years ago

可以提供一下你的结构体吗

struct Model: Codable { let gradeTabs: [GradeTab]? let grades: [Grade]? let iosConfig: IOSConfig?

enum CodingKeys: String, CodingKey {
    case gradeTabs = "grade_tabs"
    case grades
    case iosConfig = "ios"
}

}

Pircate commented 3 years ago

这样看不出问题,是否可以提供一个能跑起来的Demo。