NSObject Data 转 NSData *HTTPBody

2022-01-24  本文已影响0人  隐身人

HTTPBody

/*!
    @abstract Sets the request body data of the receiver.
    @discussion This data is sent as the message body of the request, as
    in done in an HTTP POST request.
*/
@property (nullable, copy) NSData *HTTPBody;

iOS 数据转 json data

- (NSData *)toJSONData:(id)obj{
    NSError *error = nil;
    NSData *jsonData = [NSJSONSerialization dataWithJSONObject:obj options:NSJSONWritingPrettyPrinted error:&error];
    if ([jsonData length] > 0 && error == nil){
        return jsonData;
    }else{
        return nil;
    }
}
上一篇 下一篇

猜你喜欢

热点阅读