Exception 'NSJSONReadingAssumeTopLevelDictionary and NSJSONReadingAllowFragments cannot be set at the same time'

After upgrading an Xcode to 13.0 version and recompiling my app with it on a device I started getting this exception:

libc++abi: terminating with uncaught exception of type NSException dyld4 config: DYLD_LIBRARY_PATH=/usr/lib/system/introspectionDYLD_INSERT_LIBRARIES=/Developer/usr/lib/libBacktraceRecording.dylib:/Developer/usr/lib/libMainThreadChecker.dylib:/Developer/Library/PrivateFrameworks/DTDDISupport.framework/libViewDebuggerSupport.dylib

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'NSJSONReadingAssumeTopLevelDictionary and NSJSONReadingAllowFragments cannot be set at the same time' terminating with uncaught exception of type NSException

It seems that the problem is with the new option topLevelDictionaryAssume added in JSONSerialization.ReadingOptions, available only for ios15.

What I've tried: I've checked all places where I had .allowFragments and replaced it with topLevelDictionaryAssume. It didn't help. Any advice would be appreciated.

Can you post an example of the JSON you’re trying to parse and the code you’re trying to use to parse it?

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

Sorry, I can't, there are a lot of network requests and I didn't know which one exactly could cause the trouble. But it appeared only after upgrading to xcode13.

I've solved this by replacing an options parameter in all NSJSONSerialization method calls to kNilOptions:

[NSJSONSerialization  dataWithJSONObject:dictionary options:kNilOptions error:&err];
Exception 'NSJSONReadingAssumeTopLevelDictionary and NSJSONReadingAllowFragments cannot be set at the same time'
 
 
Q