Core-fetchJSONString¶
/// 获取指定路径的原始json字符串
///
/// - Parameters:
/// - path: JSON数据路径 (默认为根路径)
/// - keys: 目标数据子路径 (例: [0, "_id"])
/// - Returns: 指定路径的原始json字符串
func fetchJSONString(path: String? = nil, keys: [JSONSubscriptType] = []) -> String
Response
转换为String
path
指定取值路径,可以设置多级,如retBody>name
,如果为nil
,取根路径""
key
在path
的前提下,再指定详细的取值路径,可为Int
或String
ps: 当前Response
的 ModelableParameterType
可以通过 MoyaMapperPlugin
进行统一设置
Example¶
""
let json = response.fetchJSONString()
print("json -- \(json)")
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"
let json = response.fetchJSONString(path: "retBody", keys: [])
print("json -- \(json)")
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"
}