|
@@ -3,6 +3,7 @@ package jsoniter
|
|
|
import (
|
|
import (
|
|
|
"fmt"
|
|
"fmt"
|
|
|
"os"
|
|
"os"
|
|
|
|
|
+ "strings"
|
|
|
)
|
|
)
|
|
|
|
|
|
|
|
func ExampleMarshal() {
|
|
func ExampleMarshal() {
|
|
@@ -93,3 +94,30 @@ func ExampleGet() {
|
|
|
// Output:
|
|
// Output:
|
|
|
// Crimson
|
|
// Crimson
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+func ExampleMapKey() {
|
|
|
|
|
+ hello := MyKey("hello")
|
|
|
|
|
+ output, _ := Marshal(map[*MyKey]string{&hello: "world"})
|
|
|
|
|
+ fmt.Println(string(output))
|
|
|
|
|
+ obj := map[*MyKey]string{}
|
|
|
|
|
+ Unmarshal(output, &obj)
|
|
|
|
|
+ for k, v := range obj {
|
|
|
|
|
+ fmt.Println(*k, v)
|
|
|
|
|
+ }
|
|
|
|
|
+ // Output:
|
|
|
|
|
+ // {"Hello":"world"}
|
|
|
|
|
+ // Hel world
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+type MyKey string
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+func (m *MyKey) MarshalText() ([]byte, error) {
|
|
|
|
|
+ return []byte(strings.Replace(string(*m), "h", "H", -1)), nil
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+func (m *MyKey) UnmarshalText(text []byte) error {
|
|
|
|
|
+ *m = MyKey(text[:3])
|
|
|
|
|
+ return nil
|
|
|
|
|
+}
|
|
|
|
|
+
|