關(guān)于AFNetworking的JSON解析之前的原始數(shù)據(jù)
項目的某個功能出現(xiàn)了bug,服務(wù)端接收到的數(shù)據(jù)有丟失,需要配合服務(wù)端的同學(xué)做調(diào)試,因此出現(xiàn)了網(wǎng)絡(luò)請求到的結(jié)構(gòu)不能被正確解析,需要獲知原始數(shù)據(jù)是長什么樣的,so,查AFNetworking的源代碼吧
在AFURLResponseSerialization的.m文件里有個方法叫:
- (nullable id)responseObjectForResponse:(nullable NSURLResponse *)response
data:(nullable NSData *)data
error:(NSError * _Nullable __autoreleasing *)error NS_SWIFT_NOTHROW;
在此方法里的
id responseObject = [NSJSONSerialization JSONObjectWithData:data options:self.readingOptions error:&serializationError];
就是它的解析事件了
其中data就是他的原始數(shù)據(jù),
NSString * str =[[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
打印一下就知道網(wǎng)絡(luò)請求到的原始數(shù)據(jù)是什么了。