Alamofire源碼解讀系列(四)之參數編碼(ParameterEncoding)

本篇講解參數編碼的內容

前言

我們在開發中發的每一個請求都是通過URLRequest來進行封裝的,可以通過一個URL生成URLRequest。那么如果我有一個參數字典,這個參數字典又是如何從客戶端傳遞到服務器的呢?

Alamofire中是這樣使用的:

  • URLEncoding 和URL相關的編碼,有兩種編碼方式:

    • 直接拼接到URL中
    • 通過request的httpBody傳值
  • JSONEncoding 把參數字典編碼成JSONData后賦值給request的httpBody

  • PropertyListEncoding把參數字典編碼成PlistData后賦值給request的httpBody

那么接下來就看看具體的實現過程是怎么樣的?

HTTPMethod

/// HTTP method definitions.
///
/// See https://tools.ietf.org/html/rfc7231#section-4.3
public enum HTTPMethod: String {
    case options = "OPTIONS"
    case get     = "GET"
    case head    = "HEAD"
    case post    = "POST"
    case put     = "PUT"
    case patch   = "PATCH"
    case delete  = "DELETE"
    case trace   = "TRACE"
    case connect = "CONNECT"
}

上邊就是Alamofire中支持的HTTPMethod,這些方法的詳細定義,可以看這篇文章:HTTP Method 詳細解讀(GET HEAD POST OPTIONS PUT DELETE TRACE CONNECT)

ParameterEncoding協議

/// A type used to define how a set of parameters are applied to a `URLRequest`.
public protocol ParameterEncoding {
    /// Creates a URL request by encoding parameters and applying them onto an existing request.
    ///
    /// - parameter urlRequest: The request to have parameters applied.
    /// - parameter parameters: The parameters to apply.
    ///
    /// - throws: An `AFError.parameterEncodingFailed` error if encoding fails.
    ///
    /// - returns: The encoded request.
    func encode(_ urlRequest: URLRequestConvertible, with parameters: Parameters?) throws -> URLRequest
}

這個協議中只有一個函數,該函數需要兩個參數:

  • urlRequest 該參數需要實現URLRequestConvertible協議,實現URLRequestConvertible協議的對象能夠轉換成URLRequest
  • parameters 參數,其類型為Parameters,也就是字典:public typealias Parameters = [String: Any]

該函數返回值類型為URLRequest。通過觀察這個函數,我們就明白了這個函數的目的就是把參數綁定到urlRequest之中,至于返回的urlRequest是不是之前的urlRequest,這個不一定,另一個比較重要的是該函數會拋出異常,因此在本篇后邊的解讀中會說明該異常的來源。

URLEncoding

我們已經知道了URLEncoding就是和URL相關的編碼。當把參數編碼到httpBody中這種情況是不受限制的,而直接編碼到URL中就會受限制,只有當HTTPMethod為GET, HEAD and DELETE時才直接編碼到URL中。

由于出現了上邊所說的不同情況,因此考慮使用枚舉來對這些情況進行設計:

 public enum Destination {
        case methodDependent, queryString, httpBody
    }

我們對Destination的子選項給出解釋:

  • methodDependent 根據HTTPMethod自動判斷采取哪種編碼方式
  • queryString 拼接到URL中
  • httpBody 拼接到httpBody中

Alamofire源碼解讀系列(一)之概述和使用中我們已經講解了如何使用Alamofire,在每個請求函數的參數中,其中有一個參數就是編碼方式。我們看看URLEncoding提供了那些初始化方法:

/// Returns a default `URLEncoding` instance.
    public static var `default`: URLEncoding { return URLEncoding() }

    /// Returns a `URLEncoding` instance with a `.methodDependent` destination.
    public static var methodDependent: URLEncoding { return URLEncoding() }

    /// Returns a `URLEncoding` instance with a `.queryString` destination.
    public static var queryString: URLEncoding { return URLEncoding(destination: .queryString) }

    /// Returns a `URLEncoding` instance with an `.httpBody` destination.
    public static var httpBody: URLEncoding { return URLEncoding(destination: .httpBody) }

    /// The destination defining where the encoded query string is to be applied to the URL request.
    public let destination: Destination

    // MARK: Initialization

    /// Creates a `URLEncoding` instance using the specified destination.
    ///
    /// - parameter destination: The destination defining where the encoded query string is to be applied.
    ///
    /// - returns: The new `URLEncoding` instance.
    public init(destination: Destination = .methodDependent) {
        self.destination = destination
    }

可以看出,默認的初始化選擇的Destination是methodDependent,除了default這個單利外,又增加了其他的三個。這里需要注意一下,單利的寫法

public static var `default`: URLEncoding { return URLEncoding() }

現在已經能夠創建URLEncoding了,是時候讓他實現ParameterEncoding協議里邊的方法了。

  /// Creates a URL request by encoding parameters and applying them onto an existing request.
    ///
    /// - parameter urlRequest: The request to have parameters applied.
    /// - parameter parameters: The parameters to apply.
    ///
    /// - throws: An `Error` if the encoding process encounters an error.
    ///
    /// - returns: The encoded request.
    public func encode(_ urlRequest: URLRequestConvertible, with parameters: Parameters?) throws -> URLRequest {
        /// 獲取urlRequest
        var urlRequest = try urlRequest.asURLRequest()

        /// 如果參數為nil就直接返回urlRequest
        guard let parameters = parameters else { return urlRequest }

        /// 把參數編碼到url的情況
        if let method = HTTPMethod(rawValue: urlRequest.httpMethod ?? "GET"), encodesParametersInURL(with: method) {
            /// 取出url
            guard let url = urlRequest.url else {
                throw AFError.parameterEncodingFailed(reason: .missingURL)
            }

            /// 分解url
            if var urlComponents = URLComponents(url: url, resolvingAgainstBaseURL: false), !parameters.isEmpty {
           
                /// 把原有的url中的query百分比編碼后在拼接上編碼后的參數
                let percentEncodedQuery = (urlComponents.percentEncodedQuery.map { $0 + "&" } ?? "") + query(parameters) 
                urlComponents.percentEncodedQuery = percentEncodedQuery
                urlRequest.url = urlComponents.url
            }
        } else { /// 編碼到httpBody的情況
            
            /// 設置Content-Type
            if urlRequest.value(forHTTPHeaderField: "Content-Type") == nil {
                urlRequest.setValue("application/x-www-form-urlencoded; charset=utf-8", forHTTPHeaderField: "Content-Type")
            }

            urlRequest.httpBody = query(parameters).data(using: .utf8, allowLossyConversion: false)
        }

        return urlRequest
    }

其實,這個函數的實現并不復雜,函數內的注釋部分就是這個函數的線索。當然,里邊還用到了兩個外部函數:encodesParametersInURLquery,這兩個函數等會解釋。函數內還用到了URLComponents這個東東,可以直接在這里https://developer.apple.com/reference/foundation/nsurl獲取詳細信息。我再這里就粗略的舉個例子來說明url的組成:

https://johnny:p4ssw0rd@www.example.com:443/script.ext;param=value?query=value#ref

這個url拆解后:

組件名稱
scheme https
user johnny
password p4ssw0rd
host www.example.com
port 443
path /script.ext
pathExtension ext
pathComponents ["/", "script.ext"]
parameterString param=value
query query=value
fragment ref

所以說,了解URL的組成很有必要,只有對網絡請求有了詳細的了解,我們才能去做網絡優化的一些事情。這些事情包括數據預加載,弱網處理等等。

上邊的代碼中出現了兩個額外的函數,我們來看看這兩個函數。首先是encodesParametersInURL:

  private func encodesParametersInURL(with method: HTTPMethod) -> Bool {
        switch destination {
        case .queryString:
            return true
        case .httpBody:
            return false
        default:
            break
        }

        switch method {
        case .get, .head, .delete:
            return true
        default:
            return false
        }
    }

這個函數的目的是判斷是不是要把參數拼接到URL之中,如果destination選的是queryString就返回true,如果是httpBody,就返回false,然后再根據method判斷,只有get,head,delete才返回true,其他的返回false。

如果該函數返回的結果是true,那么就把參數拼接到request的url中,否則拼接到httpBody中。

這里簡單介紹下swift中的權限關鍵字:open, public, fileprivate, private:

  • open 該權限是最大的權限,允許訪問文件,同時允許繼承
  • public 允許訪問但不允許繼承
  • fileprivate 允許文件內訪問
  • private 只允許當前對象的代碼塊內部訪問

另外一個函數是query,別看這個函數名很短,但是這個函數內部又嵌套了其他的函數,而且這個函數才是核心函數,它的主要功能是把參數處理成字符串,這個字符串也是做過編碼處理的:

 private func query(_ parameters: [String: Any]) -> String {
        var components: [(String, String)] = []

        for key in parameters.keys.sorted(by: <) {
            let value = parameters[key]!
            components += queryComponents(fromKey: key, value: value)
        }

        return components.map { "\($0)=\($1)" }.joined(separator: "&")
    }

參數是一個字典,key的類型是String,但value的類型是any,也就是說value不一定是字符串,也有可能是數組或字典,因此針對value需要做進一步的處理。我們在寫代碼的過程中,如果出現了這種特殊情況,且是我們已經考慮到了的情況,我們就應該考慮使用函數做專門的處理了。

上邊函數的整體思路是:

  • 寫一個數組,這個數組中存放的是元組數據,元組中存放的是key和字符串類型的value
  • 遍歷參數,對參數做進一步的處理,然后拼接到數組中
  • 進一步處理數組內部的元組數據,把元組內部的數據用=號拼接,然后用符號&把數組拼接成字符串

上邊函數中使用了一個額外函數queryComponents。這個函數的目的是處理value,我們看看這個函數的內容:

 /// Creates percent-escaped, URL encoded query string components from the given key-value pair using recursion.
    ///
    /// - parameter key:   The key of the query component.
    /// - parameter value: The value of the query component.
    ///
    /// - returns: The percent-escaped, URL encoded query string components.
    public func queryComponents(fromKey key: String, value: Any) -> [(String, String)] {
        var components: [(String, String)] = []

        if let dictionary = value as? [String: Any] {
            for (nestedKey, value) in dictionary {
                components += queryComponents(fromKey: "\(key)[\(nestedKey)]", value: value)
            }
        } else if let array = value as? [Any] {
            for value in array {
                components += queryComponents(fromKey: "\(key)[]", value: value)
            }
        } else if let value = value as? NSNumber {
            if value.isBool {
                components.append((escape(key), escape((value.boolValue ? "1" : "0"))))
            } else {
                components.append((escape(key), escape("\(value)")))
            }
        } else if let bool = value as? Bool {
            components.append((escape(key), escape((bool ? "1" : "0"))))
        } else {
            components.append((escape(key), escape("\(value)")))
        }

        return components
    }

該函數內部使用了遞歸。針對字典中的value的情況做了如下幾種情況的處理:

  • [String: Any] 如果value依然是字典,那么調用自身,也就是做遞歸處理

  • [Any] 如果value是數組,遍歷后依然調用自身。把數組拼接到url中的規則是這樣的。假如有一個數組["a", "b", "c"],拼接后的結果是key[]="a"&key[]="b"&key[]="c"

  • NSNumber 如果value是NSNumber,要做進一步的判斷,判斷這個NSNumber是不是表示布爾類型。這里引入了一個額外的函數escape,我們馬上就會給出說明。

      extension NSNumber {
          fileprivate var isBool: Bool { return CFBooleanGetTypeID() == CFGetTypeID(self) }
      }
    
  • Bool 如果是Bool,轉義后直接拼接進數組

  • 其他情況,轉義后直接拼接進數組

上邊函數中的key已經是字符串類型了,那么為什么還要進行轉義的?這是因為在url中有些字符是不允許的。這些字符會干擾url的解析。按照RFC 3986的規定,下邊的這些字符必須要做轉義的:

:#[]@!$&'()*+,;=

?/可以不用轉義,但是在某些第三方的SDk中依然需要轉義,這個要特別注意。而轉義的意思就是百分號編碼。要了解百分號編碼的詳細內容,可以看我轉債的這篇文章url 編碼(percentcode 百分號編碼)(轉載)

來看看這個escape函數:

/// Returns a percent-escaped string following RFC 3986 for a query string key or value.
    ///
    /// RFC 3986 states that the following characters are "reserved" characters.
    ///
    /// - General Delimiters: ":", "#", "[", "]", "@", "?", "/"
    /// - Sub-Delimiters: "!", "$", "&", "'", "(", ")", "*", "+", ",", ";", "="
    ///
    /// In RFC 3986 - Section 3.4, it states that the "?" and "/" characters should not be escaped to allow
    /// query strings to include a URL. Therefore, all "reserved" characters with the exception of "?" and "/"
    /// should be percent-escaped in the query string.
    ///
    /// - parameter string: The string to be percent-escaped.
    ///
    /// - returns: The percent-escaped string.
    public func escape(_ string: String) -> String {
        let generalDelimitersToEncode = ":#[]@" // does not include "?" or "/" due to RFC 3986 - Section 3.4
        let subDelimitersToEncode = "!$&'()*+,;="

        var allowedCharacterSet = CharacterSet.urlQueryAllowed
        allowedCharacterSet.remove(charactersIn: "\(generalDelimitersToEncode)\(subDelimitersToEncode)")

        var escaped = ""

        //==========================================================================================================
        //
        //  Batching is required for escaping due to an internal bug in iOS 8.1 and 8.2. Encoding more than a few
        //  hundred Chinese characters causes various malloc error crashes. To avoid this issue until iOS 8 is no
        //  longer supported, batching MUST be used for encoding. This introduces roughly a 20% overhead. For more
        //  info, please refer to:
        //
        //      - https://github.com/Alamofire/Alamofire/issues/206
        //
        //==========================================================================================================

        if #available(iOS 8.3, *) {
            escaped = string.addingPercentEncoding(withAllowedCharacters: allowedCharacterSet) ?? string
        } else {
            let batchSize = 50
            var index = string.startIndex

            while index != string.endIndex {
                let startIndex = index
                let endIndex = string.index(index, offsetBy: batchSize, limitedBy: string.endIndex) ?? string.endIndex
                let range = startIndex..<endIndex

                let substring = string.substring(with: range)

                escaped += substring.addingPercentEncoding(withAllowedCharacters: allowedCharacterSet) ?? substring

                index = endIndex
            }
        }

        return escaped
    }

該函數的思路也很簡單,使用了系統自帶的函數來進行百分號編碼,值得注意的是,如果系統小于8.3需要做特殊的處理,正好在這個處理中,我們研究一下swift中Range的用法。

對于一個string,他的范圍是從string.startIndexstring.endIndex的。通過public func index(_ i: String.Index, offsetBy n: String.IndexDistance, limitedBy limit: String.Index) -> String.Index?函數可以取一個范圍,這里中重要的就是index的概念,然后通過startIndex..<endIndex就生成了一個Range,利用這個Range就能截取字符串了。關于Range更多的用法,請參考蘋果官方文檔。

到這里,URLEncoding的全部內容就分析完畢了,我們把不同的功能劃分成不同的函數,這種做法最大的好處就是我們可以使用單獨的函數做獨立的事情。我完全可以使用escape這個函數轉義任何字符串。

JSONEncoding

JSONEncoding的主要作用是把參數以JSON的形式編碼到request之中,當然是通過request的httpBody進行賦值的。JSONEncoding提供了兩種處理函數,一種是對普通的字典參數進行編碼,另一種是對JSONObject進行編碼,處理這兩種情況的函數基本上是相同的,在下邊會做出統一的說明。

我們先看看初始化方法:

    /// Returns a `JSONEncoding` instance with default writing options.
    public static var `default`: JSONEncoding { return JSONEncoding() }

    /// Returns a `JSONEncoding` instance with `.prettyPrinted` writing options.
    public static var prettyPrinted: JSONEncoding { return JSONEncoding(options: .prettyPrinted) }

    /// The options for writing the parameters as JSON data.
    public let options: JSONSerialization.WritingOptions

    // MARK: Initialization

    /// Creates a `JSONEncoding` instance using the specified options.
    ///
    /// - parameter options: The options for writing the parameters as JSON data.
    ///
    /// - returns: The new `JSONEncoding` instance.
    public init(options: JSONSerialization.WritingOptions = []) {
        self.options = options
    }

這里邊值得注意的是JSONSerialization.WritingOptions,也就是JSON序列化的寫入方式。WritingOptions是一個結構體,系統提供了一個選項:prettyPrinted,意思是更好的打印效果。

接下來看看下邊的兩個函數:

 /// Creates a URL request by encoding parameters and applying them onto an existing request.
    ///
    /// - parameter urlRequest: The request to have parameters applied.
    /// - parameter parameters: The parameters to apply.
    ///
    /// - throws: An `Error` if the encoding process encounters an error.
    ///
    /// - returns: The encoded request.
    public func encode(_ urlRequest: URLRequestConvertible, with parameters: Parameters?) throws -> URLRequest {
        var urlRequest = try urlRequest.asURLRequest()

        guard let parameters = parameters else { return urlRequest }

        do {
            let data = try JSONSerialization.data(withJSONObject: parameters, options: options)

            if urlRequest.value(forHTTPHeaderField: "Content-Type") == nil {
                urlRequest.setValue("application/json", forHTTPHeaderField: "Content-Type")
            }

            urlRequest.httpBody = data
        } catch {
            throw AFError.parameterEncodingFailed(reason: .jsonEncodingFailed(error: error))
        }

        return urlRequest
    }

    /// Creates a URL request by encoding the JSON object and setting the resulting data on the HTTP body.
    ///
    /// - parameter urlRequest: The request to apply the JSON object to.
    /// - parameter jsonObject: The JSON object to apply to the request.
    ///
    /// - throws: An `Error` if the encoding process encounters an error.
    ///
    /// - returns: The encoded request.
    public func encode(_ urlRequest: URLRequestConvertible, withJSONObject jsonObject: Any? = nil) throws -> URLRequest {
        var urlRequest = try urlRequest.asURLRequest()

        guard let jsonObject = jsonObject else { return urlRequest }

        do {
            let data = try JSONSerialization.data(withJSONObject: jsonObject, options: options)

            if urlRequest.value(forHTTPHeaderField: "Content-Type") == nil {
                urlRequest.setValue("application/json", forHTTPHeaderField: "Content-Type")
            }

            urlRequest.httpBody = data
        } catch {
            throw AFError.parameterEncodingFailed(reason: .jsonEncodingFailed(error: error))
        }

        return urlRequest
    }

第一個函數實現了ParameterEncoding協議,第二個參數作為擴展,函數中最核心的內容是把參數變成Data類型,然后給httpBody賦值,需要注意的是異常處理。

PropertyListEncoding

PropertyListEncoding的處理方式和JSONEncoding的差不多,為了節省篇幅,就不做出解答了。直接上源碼:

/// Uses `PropertyListSerialization` to create a plist representation of the parameters object, according to the
/// associated format and write options values, which is set as the body of the request. The `Content-Type` HTTP header
/// field of an encoded request is set to `application/x-plist`.
public struct PropertyListEncoding: ParameterEncoding {

    // MARK: Properties

    /// Returns a default `PropertyListEncoding` instance.
    public static var `default`: PropertyListEncoding { return PropertyListEncoding() }

    /// Returns a `PropertyListEncoding` instance with xml formatting and default writing options.
    public static var xml: PropertyListEncoding { return PropertyListEncoding(format: .xml) }

    /// Returns a `PropertyListEncoding` instance with binary formatting and default writing options.
    public static var binary: PropertyListEncoding { return PropertyListEncoding(format: .binary) }

    /// The property list serialization format.
    public let format: PropertyListSerialization.PropertyListFormat

    /// The options for writing the parameters as plist data.
    public let options: PropertyListSerialization.WriteOptions

    // MARK: Initialization

    /// Creates a `PropertyListEncoding` instance using the specified format and options.
    ///
    /// - parameter format:  The property list serialization format.
    /// - parameter options: The options for writing the parameters as plist data.
    ///
    /// - returns: The new `PropertyListEncoding` instance.
    public init(
        format: PropertyListSerialization.PropertyListFormat = .xml,
        options: PropertyListSerialization.WriteOptions = 0)
    {
        self.format = format
        self.options = options
    }

    // MARK: Encoding

    /// Creates a URL request by encoding parameters and applying them onto an existing request.
    ///
    /// - parameter urlRequest: The request to have parameters applied.
    /// - parameter parameters: The parameters to apply.
    ///
    /// - throws: An `Error` if the encoding process encounters an error.
    ///
    /// - returns: The encoded request.
    public func encode(_ urlRequest: URLRequestConvertible, with parameters: Parameters?) throws -> URLRequest {
        var urlRequest = try urlRequest.asURLRequest()

        guard let parameters = parameters else { return urlRequest }

        do {
            let data = try PropertyListSerialization.data(
                fromPropertyList: parameters,
                format: format,
                options: options
            )

            if urlRequest.value(forHTTPHeaderField: "Content-Type") == nil {
                urlRequest.setValue("application/x-plist", forHTTPHeaderField: "Content-Type")
            }

            urlRequest.httpBody = data
        } catch {
            throw AFError.parameterEncodingFailed(reason: .propertyListEncodingFailed(error: error))
        }

        return urlRequest
    }
}

JSONStringArrayEncoding

這是Alamofire種對字符串數組編碼示例。原理也很簡單,直接上代碼:

public struct JSONStringArrayEncoding: ParameterEncoding {
    public let array: [String]
    
    public init(array: [String]) {
        self.array = array
    }
    
    public func encode(_ urlRequest: URLRequestConvertible, with parameters: Parameters?) throws -> URLRequest {
        var urlRequest = urlRequest.urlRequest
        
        let data = try JSONSerialization.data(withJSONObject: array, options: [])
        
        if urlRequest!.value(forHTTPHeaderField: "Content-Type") == nil {
            urlRequest!.setValue("application/json", forHTTPHeaderField: "Content-Type")
        }
        
        urlRequest!.httpBody = data
        
        return urlRequest!
    }
}

總結

只有了解了某個功能的內部實現原理,我們才能更好的使用這個功能。沒毛病。

由于知識水平有限,如有錯誤,還望指出

鏈接

Alamofire源碼解讀系列(一)之概述和使用 簡書博客園

Alamofire源碼解讀系列(二)之錯誤處理(AFError) 簡書博客園

Alamofire源碼解讀系列(三)之通知處理(Notification) 簡書博客園

最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。
  • 序言:七十年代末,一起剝皮案震驚了整個濱河市,隨后出現的幾起案子,更是在濱河造成了極大的恐慌,老刑警劉巖,帶你破解...
    沈念sama閱讀 230,527評論 6 544
  • 序言:濱河連續發生了三起死亡事件,死亡現場離奇詭異,居然都是意外死亡,警方通過查閱死者的電腦和手機,發現死者居然都...
    沈念sama閱讀 99,687評論 3 429
  • 文/潘曉璐 我一進店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人,你說我怎么就攤上這事。” “怎么了?”我有些...
    開封第一講書人閱讀 178,640評論 0 383
  • 文/不壞的土叔 我叫張陵,是天一觀的道長。 經常有香客問我,道長,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 63,957評論 1 318
  • 正文 為了忘掉前任,我火速辦了婚禮,結果婚禮上,老公的妹妹穿的比我還像新娘。我一直安慰自己,他們只是感情好,可當我...
    茶點故事閱讀 72,682評論 6 413
  • 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著,像睡著了一般。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發上,一...
    開封第一講書人閱讀 56,011評論 1 329
  • 那天,我揣著相機與錄音,去河邊找鬼。 笑死,一個胖子當著我的面吹牛,可吹牛的內容都是我干的。 我是一名探鬼主播,決...
    沈念sama閱讀 44,009評論 3 449
  • 文/蒼蘭香墨 我猛地睜開眼,長吁一口氣:“原來是場噩夢啊……” “哼!你這毒婦竟也來了?” 一聲冷哼從身側響起,我...
    開封第一講書人閱讀 43,183評論 0 290
  • 序言:老撾萬榮一對情侶失蹤,失蹤者是張志新(化名)和其女友劉穎,沒想到半個月后,有當地人在樹林里發現了一具尸體,經...
    沈念sama閱讀 49,714評論 1 336
  • 正文 獨居荒郊野嶺守林人離奇死亡,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內容為張勛視角 年9月15日...
    茶點故事閱讀 41,435評論 3 359
  • 正文 我和宋清朗相戀三年,在試婚紗的時候發現自己被綠了。 大學時的朋友給我發了我未婚夫和他白月光在一起吃飯的照片。...
    茶點故事閱讀 43,665評論 1 374
  • 序言:一個原本活蹦亂跳的男人離奇死亡,死狀恐怖,靈堂內的尸體忽然破棺而出,到底是詐尸還是另有隱情,我是刑警寧澤,帶...
    沈念sama閱讀 39,148評論 5 365
  • 正文 年R本政府宣布,位于F島的核電站,受9級特大地震影響,放射性物質發生泄漏。R本人自食惡果不足惜,卻給世界環境...
    茶點故事閱讀 44,838評論 3 350
  • 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧,春花似錦、人聲如沸。這莊子的主人今日做“春日...
    開封第一講書人閱讀 35,251評論 0 28
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽。三九已至,卻和暖如春,著一層夾襖步出監牢的瞬間,已是汗流浹背。 一陣腳步聲響...
    開封第一講書人閱讀 36,588評論 1 295
  • 我被黑心中介騙來泰國打工, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留,地道東北人。 一個月前我還...
    沈念sama閱讀 52,379評論 3 400
  • 正文 我出身青樓,卻偏偏與公主長得像,于是被迫代替她去往敵國和親。 傳聞我的和親對象是個殘疾皇子,可洞房花燭夜當晚...
    茶點故事閱讀 48,627評論 2 380

推薦閱讀更多精彩內容