douhu2890 2019-09-10 09:26
浏览 43

为什么我在运行时会得到空的json? [重复]

I was trying to follow this tutorial:

https://gowebexamples.com/json/

and personalised it a bit, so instead of having the User struct like:

type User struct {
    Firstname string `json:"firstname"`
    Lastname  string `json:"lastname"`
    Age       int    `json:"age"`
}

I had it like:

type User struct {
    firstName string `json:"first_name"`
    lastName  string `json:"last_name"`
    age       int    `json:"age"`
}

doing the call, with the correct json fields I would get empty strings in the name and 0 for the age...

I copied the code and pasted it so that I was sure the problem was my code(it was). Turns out the problem was because my User fields were not capitalised... if I have u.firstname it does not work, but if I have u.Firstname it works...

I fixed my code but now I cant understand why is it that the name of the fields in the struct not being capitalised are the problem, can someone please explain that to my dumb ass brain?

Thanks.

</div>
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 孟德尔随机化结果不一致
    • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
    • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
    • ¥15 谁有desed数据集呀
    • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
    • ¥15 关于#hadoop#的问题
    • ¥15 (标签-Python|关键词-socket)
    • ¥15 keil里为什么main.c定义的函数在it.c调用不了
    • ¥50 切换TabTip键盘的输入法
    • ¥15 可否在不同线程中调用封装数据库操作的类