正常狀況: func main() { str := `{"expires_in":2592000,"refresh_token":"22.84564433384c3dffdf8c2b123b6da8de.315360000.1756090115.2605827041-6701125","access_token":"21.060aaae1049e2604d0fa71d992aea516.2592000.1443322115.2605827041-6701125","session_secret":"6ce3910403a953006916f1fafef433c5","session_key":"9mnRdL3CfpvaeMqn4g2A4f1b+olbN4iD079GhsDIumsoSy9AYZgVtDs2XO5FsHMys+AxZtyqVtQSjkSZtilJd1UAsAoNxI9esg==","scope ":"basic"}` var m map[string]interface{} json.Unmarshal([]byte(str), &m) fmt.Println(m) } ============================================================== 控制檯打印: map[session_secret:6ce3910403a953006916f1fafef433c5 session_key:9mnRdL3CfpvaeMqn4g2A4f1b+olbN4iD079GhsDIumsoSy9AYZgVtDs2XO5FsHMys+AxZtyqVtQSjkSZtilJd1UAsAoNxI9esg== scope :basic expires_in:2.592e+06 r efresh_token:22.84564433384c3dffdf8c2b123b6da8de.315360000.1756090115.2605827041-6701125 access_token:21.060aaae1049e2604d0fa71d992aea516.2592000.1443322115.2605827041-6701125]
json串有換行 func main() { str := `{"expires_in":2592000,"refresh_token":"22.18aba8ebd4838130f9506f35f93a3ca2.315360000.1756092980.2605827041-6701125","access_token":"21.27 4921d56f67b0a2e2bf988bd695fbe7.2592000.1443324980.2605827041-6701125","session_secret":"21376476ea4eac56c3382883796615a8","session_key":"9mnRdvXn5BQJ3 wGCnC\/UBA7DUyVivKDymYcPkNnFkrqS0n7OjAhiTGeKjAlDLSLs7h\/\/CibfnC8VZFJd+u8SZ02fpvHxlBPa7w==","scope":"basic"}` var m map[string]interface{} json.Unmarshal([]byte(str), &m) fmt.Println(m) } ===================================================== 控制檯打印: map[]
疑惑:json串來自第三方平臺反饋 ,我手動將帶有換行的json串調好格式能夠解析,在撤銷修改不能解析,可是在手動改好的串中手動製造換行卻仍然能夠解析json