Fix some md err
This commit is contained in:
@@ -21,6 +21,7 @@ Suppose we have the JSON in the above example. How can we parse this data and ma
|
||||
func Unmarshal(data []byte, v interface{}) error
|
||||
```
|
||||
We can use this function like so:
|
||||
|
||||
```Go
|
||||
package main
|
||||
|
||||
@@ -69,12 +70,12 @@ Suppose we have the following JSON data:
|
||||
b := []byte(`{"Name":"Wednesday","Age":6,"Parents":["Gomez","Morticia"]}`)
|
||||
```
|
||||
Now we parse this JSON to an interface{}:
|
||||
```Go`
|
||||
```Go
|
||||
var f interface{}
|
||||
err := json.Unmarshal(b, &f)
|
||||
```
|
||||
The `f` stores a map, where keys are strings and values are interface{}'s'.
|
||||
```Go`
|
||||
```Go
|
||||
f = map[string]interface{}{
|
||||
"Name": "Wednesday",
|
||||
"Age": 6,
|
||||
@@ -85,7 +86,7 @@ The `f` stores a map, where keys are strings and values are interface{}'s'.
|
||||
}
|
||||
```
|
||||
So, how do we access this data? Type assertion.
|
||||
```Go`
|
||||
```Go
|
||||
m := f.(map[string]interface{})
|
||||
```
|
||||
After asserted, you can use the following code to access data:
|
||||
|
||||
@@ -103,9 +103,9 @@ The following functions are from the `strconv` package. As usual, please see off
|
||||
str = strconv.AppendQuoteRune(str, '单')
|
||||
fmt.Println(string(str))
|
||||
}
|
||||
|
||||
```
|
||||
- Format series, convert other data types into string.
|
||||
|
||||
```Go
|
||||
package main
|
||||
|
||||
import (
|
||||
|
||||
Reference in New Issue
Block a user