跳转至

Rx-fetchJSONString

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

func fetchJSONString(path: String? = nil, keys: [JSONSubscriptType] = []) -> Single<String>

详细说明请参考 Core 目录下的 fetchJSONString ,这里就不再赘述


Example

let rxRequest: Single<Response>

success-obj

  • ""
rxRequest.fetchJSONString()
    .subscribe(onSuccess: { json in
        print("json -- \(json)")
    }).disposed(by: disposeBag
json -- {
  "retStatus" : "000",
  "retMsg" : "获取数据成功",
  "retBody" : {
    "name" : "MoyaMapper",
    "organization" : "https:\/\/github.com\/MoyaMapper",
    "github" : "https:\/\/github.com\/LinXunFeng",
    "avatar" : "https:\/\/avatars0.githubusercontent.com\/u\/19367531?s=460&v=4",
    "age" : 23,
    "author" : "LinXunFeng",
    "logoUrl" : "https:\/\/github.com\/MoyaMapper\/MoyaMapper.github.io\/raw\/master\/img\/MoyaMapper.png"
  }
}
  • "retBody"
rxRequest.fetchJSONString(path: "retBody", keys: [])
    .subscribe(onSuccess: { json in
        print("json -- \(json)")
    }).disposed(by: disposeBag
json -- {
  "name" : "MoyaMapper",
  "organization" : "https:\/\/github.com\/MoyaMapper",
  "github" : "https:\/\/github.com\/LinXunFeng",
  "avatar" : "https:\/\/avatars0.githubusercontent.com\/u\/19367531?s=460&v=4",
  "age" : 23,
  "author" : "LinXunFeng",
  "logoUrl" : "https:\/\/github.com\/MoyaMapper\/MoyaMapper.github.io\/raw\/master\/img\/MoyaMapper.png"
}