美文网首页
NSObject Data 转 NSData *HTTPBody

NSObject Data 转 NSData *HTTPBody

作者: 隐身人 | 来源:发表于2022-01-24 17:36 被阅读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;
        }
    }
    

    相关文章

      网友评论

          本文标题:NSObject Data 转 NSData *HTTPBody

          本文链接:https://www.haomeiwen.com/subject/legbhrtx.html