跳转至

Core-fetchString

/// 获取指定路径的字符串
///
/// - Parameters:
///   - path: JSON数据路径 (默认为模型数据路径)
///   - keys: 目标数据子路径  (例: [0, "_id"])
/// - Returns: 指定路径的字符串
func fetchString(path: String? = nil, keys: [JSONSubscriptType] = []) -> String

Response 转换为 String

  • path 指定取值路径,可以设置多级,如 retBody>name ,如果为 nil ,则取当前 ResponseModelableParameterTypemodelKey
  • keypath的前提下,再指定详细的取值路径,可为 IntString

ps: 当前ResponseModelableParameterType 可以通过 MoyaMapperPlugin 进行统一设置


Example

success-obj

let name = response.fetchString(path: "retBody>name") 
print("name -- \(name)")

// name -- MoyaMapper

success-array

let github = response.fetchString(path: "retBody", keys: [1, "github"])
print("github -- \(github)")

// github -- https://github.com/LinXunFeng/RxSwiftDemo