doumu9799 2017-02-18 17:36
浏览 638
已采纳

如何在Struct Golang中压缩Json

package questionnaire

import (
    "encoding/json"
)

type Items []Item

type CreateData struct {
    Items []Item
}

type Item struct {
    Id        enter code herestring `json:"id"        required:"true"`
    CompCd    string `json:"compCd"    required:"true"`
    OrgCd     string `json:"orgCd"`
    QstnId    string `json:"qstnId"    required:"true"`
    QstnIdSeq string `json:"qstnIdSeq" required:"true"`
    CustId    string `json:"custId"`
    AnsDts    string `json:"ansDts"    required:"true"`
    AnsRout   string `json:"ansRout"   required:"true"`
    QCd01     string `json:"qCd01"`
    QKey01    string `json:"qKey01"`
    QStc01    string `json:"qStc01"`
    QCat01    string `json:"qCat01"`
    Pont01    string `json:"pont01"`
    PCat01    string `json:"pCat01"`
    Comt01    string `json:"comt01"`
    QCd02     string `json:"qCd02"`
    QKey02    string `json:"qKey02"`
    QStc02    string `json:"qStc02"`
    QCat02    string `json:"qCat02"`
    Pont02    string `json:"pont02"`
    PCat02    string `json:"pCat02"`
    Comt02    string `json:"comt02"`
    .
    .
    .
    QCd50     string `json:"qCd50"`
    QKey50    string `json:"qKey50"`
    QStc50    string `json:"qStc50"`
    QCat50    string `json:"qCat50"`
    Pont50    string `json:"pont50"`
    PCat50    string `json:"pCat50"`
    Comt50    string `json:"comt50"
}

I'm newbie. I just learn go language a few day before.. My problem: How to compact this Item struct block. If i write from QCd01 to QCd50 this code can run but so bad! Sorry I'm not good at English.

  • 写回答

1条回答

  • douya6229 2017-02-24 21:17
    关注

    I copied and pasted the code in your comment. It was missing the ending } to finish the json string. Also, you need a struct to tie the items map to. Here is a working playground link.

    EDIT: I didn't realize there would be more than one "items", which I should have assumed given the plural name. Here is an updated playground link that takes care of that.

    https://play.golang.org/p/5T2C6KrVOD

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

报告相同问题?

悬赏问题

  • ¥15 arduino控制ps2手柄一直报错
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥85 maple软件,solve求反函数,出现rootof怎么办?
  • ¥15 求chat4.0解答一道线性规划题,用lingo编程运行,第一问要求写出数学模型和lingo语言编程模型,第二问第三问解答就行,我的ddl要到了谁来求了
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥65 汇编语言除法溢出问题
  • ¥15 Visual Studio问题
  • ¥20 求一个html代码,有偿
  • ¥100 关于使用MATLAB中copularnd函数的问题