代码:
package main
import (
"fmt"
gojsonq "github.com/thedevsaddam/gojsonq/v2"
"io/ioutil"
"log"
"net/http"
"strings"
)
func main() {
req, err := http.NewRequest("POST", "https://api.shuidichou.com/api/cf/v4/suspected-case/list",
strings.NewReader("pageNum=1&pageSize=20&AuthorizationV2=83zrWEfMG7fLrQr_qS_PCQIoZWJrymYBWbSXyUOKRDQ%3D"))
if err != nil {
log.Fatal(err)
}
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
resp, err := http.DefaultClient.Do(req)
if err != nil {
log.Fatal(err)
}
byts, err := ioutil.ReadAll(resp.Body)
defer resp.Body.Close()
if err != nil {
log.Fatal(err)
}
fmt.Println(string(byts))
errno := gojsonq.New().FromString(string(byts)).Find("code")
fmt.Println("错误码:", errno)
}
输出结果:
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/a339be864356d990ab4f9e707dcc237d.png#pic_center)