-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
let's convert left key to string ^^ problem #1
- Loading branch information
Showing
1 changed file
with
17 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,27 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"strconv" | ||
) | ||
|
||
func decode(input interface{}) interface{} { | ||
switch in := input.(type) { | ||
case map[interface{}]interface{}: | ||
rec := map[string]interface{}{} | ||
for k, v := range in { | ||
rec[k.(string)] = decode(v) | ||
|
||
switch k.(type) { | ||
case bool: | ||
rec[strconv.FormatBool(k.(bool))] = decode(v) | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
EVODelavega
|
||
case int: | ||
rec[strconv.Itoa(k.(int))] = decode(v) | ||
case float64: | ||
rec[fmt.Sprintf("%f", k.(float64))] = decode(v) | ||
case string: | ||
rec[k.(string)] = decode(v) | ||
} | ||
|
||
} | ||
return rec | ||
case []interface{}: | ||
|
Why type assert
k
?switch kValue := k.(type)
, then usekValue
as the type that it is