dtj2ww9500 2019-08-18 03:25
浏览 13
已采纳

无法解析go中的json文件[重复]

This question already has an answer here:

I'm trying to parse a json file using GoLang but it seems like not work. Am I doing right?

this is my Go Code:

package main

import (
    "encoding/json"
    "fmt"
    "io/ioutil"
)

type info struct {
    username   string   `json:"username"`
    password   string   `json:"password"`
    timedelay  int      `json:"timedelay"`
    courselist []string `json:"courselist"`
}

func main() {
    var jsonParse info
    file, err := ioutil.ReadFile("info.json")
    if err != nil {
        fmt.Println(err)
    }
    fmt.Println("My file content is:
", string(file))
    fmt.Println("---------------Parsing Json File----------------")

    json.Unmarshal(file, &jsonParse)
    fmt.Println("My Json Parse is:
", jsonParse)

}

and this is my json file

{
    "username" : "17020726",
    "password": "Blueflower",
    "timedelay": 200,
    "courselist": ["54"]
}

this is result of my code

My file content is:
 {
    "username" : "17020726",
    "password": "Blueflower",
    "timedelay": 200,
    "courselist": ["54"]
}
---------------Parsing Json File----------------
My Json Parse is:
 {  0 []}
</div>
  • 写回答

1条回答 默认 最新

  • duanpu1963 2019-08-18 03:43
    关注

    The info struct fields are private. Capitalize the first letters.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度