对象中使用 String 类型 接收 json(数组,字典) 时,不是原始json 字符串,而是{key1="value1"; key2="value2"}
- Dominant language
- Swift
- Stars
- 4.3k
- Forks
- 677
- PR merge metrics
- No merged PRs in 30d
Description
static func _transform(from object: Any) -> String? {
switch object {
case let str as String:
return str
case let num as NSNumber:
// Boolean Type Inside
if NSStringFromClass(type(of: num)) == "__NSCFBoolean" {
if num.boolValue {
return "true"
} else {
return "false"
}
}
return formatter.string(from: num)
case _ as NSNull:
return nil
case let obj as NSDictionary:// 新加
let data = try? JSONSerialization.data(withJSONObject: obj, options: JSONSerialization.WritingOptions.init(rawValue: 0))
let jsonStr = NSString(data: data!, encoding: String.Encoding.utf8.rawValue)
return jsonStr! as String
case let obj as NSArray:// 新加
let data = try? JSONSerialization.data(withJSONObject: obj, options: JSONSerialization.WritingOptions.init(rawValue: 0))
let jsonStr = NSString(data: data!, encoding: String.Encoding.utf8.rawValue)
return jsonStr! as String
default:
return "\(object)"
}
}
Contributor guide
No contributing guide indexed for this repository
Research direction
Locate the `_transform(from object: Any)` entry point shown in the issue and inspect the existing conversion path for NSDictionary and NSArray. Reproduce the report with a String property receiving a JSON object or array, then verify that the result is the original JSON string rather than the displayed dictionary or array form.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- swift
- Domain
- backend-api-design
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100