How do you get mutable dictionaries from AFNetwork

2019-04-14 03:04发布

I'm using JSONKit with AFNetworking's AFHTTPClient (with AFJSONRequestOperation) and I can't seem to figure out how one might trigger the use of the mutableObjectFrom... methods of JSONKit rather than the normal parser methods which return (or arrays of) JKDictionary.

Is this possible without modifying AFNetworking?

3条回答
倾城 Initia
2楼-- · 2019-04-14 03:16

For NSJSONSerialization based operation of AFNetworking, in AFJSONUtilities.m line 203, change:

NSUInteger readOptions = 0

to

NSUInteger readOptions =  NSJSONReadingMutableContainers 
查看更多
淡お忘
3楼-- · 2019-04-14 03:26

In the latest version of AFNetworking, you can achieve this without modifying code. After you create a AFJSONRequestOperation *operation & before you call [operation start], add

[operation setJSONReadingOptions:NSJSONReadingMutableContainers];

You can then iterate through the JSON and modify the underlying NSMutableDictionaries

查看更多
beautiful°
4楼-- · 2019-04-14 03:29

You can't do that without editing AFNetworking code.

In AFJSONUtilities.m change (line 103)

SEL _JSONKitSelector = NSSelectorFromString(@"objectFromJSONDataWithParseOptions:error:"); 

By

SEL _JSONKitSelector = NSSelectorFromString(@"mutableObjectFromJSONDataWithParseOptions:error:"); 
查看更多
登录 后发表回答