dqo88037 2018-09-05 19:19
浏览 375
已采纳

如何在golang中键入混合类型的数组?

I'm writing out a map which I need to convert to JSON, and one of the required values is an array of mixed type.

var models = map[string]interface{} {
   ...
   "req": [[0, "all", [0]]],
   ...
}

Is there a way to assign a type to this nested array? Or is there a better approach for creating this JSON than a map?

Edit: Getting closer I think, unsure what to do about the nested arrays

var models = map[string]interface{} {
       ...
       "req": []interface{}{[[0, "all", [0]]]},
       ...
    }

Edit: The entire JSON I'm looking to create, I'm just stuck on the "req" key, but since it was requested:

{
    1388596687391: {
      veArs: [],
      name: 'Basic-f15d2',
      tags: ['Tag'],
      did: 1435588830424,
      usn: -1,
      req: [[0, 'all', [0]]],
      flds: [
        {
          name: 'Front',
          media: [],
          sticky: false,
          rtl: false,
          ord: 0,
          font: 'Arial',
          size: 20
        },
        {
          name: 'Back',
          media: [],
          sticky: false,
          rtl: false,
          ord: 1,
          font: 'Arial',
          size: 20
        }
      ],
      sortf: 0,
      latexPre:
        '\\documentclass[12pt]{article}
\\special{papersize=3in,5in}
\\usepackage[utf8]{inputenc}
\\usepackage{amssymb,amsmath}
\\pagestyle{empty}
\\setlength{\\parindent}{0in}
\\begin{document}
',
      tmpls: [
        {
          name: 'Card 1',
          qfmt: questionFormat,
          did: null,
          bafmt: '',
          afmt: answerFormat,
          ord: 0,
          bqfmt: ''
        }
      ],
      latexPost: '\\end{document}',
      type: 0,
      id: 1388596687391,
      css,
      mod: 1435645658
    }
  }
  • 写回答

2条回答

      报告相同问题?

      相关推荐 更多相似问题

      悬赏问题

      • ¥50 关于#python#的问题,如何解决?
      • ¥15 关于git的一些问题
      • ¥15 有关python的问题
      • ¥15 vs2010 重新生成项目时显示Keycode不能为NULL
      • ¥15 用MATLAB解决问题,需要代码
      • ¥45 关于C语言设计井字棋游戏问题的实现
      • ¥20 vuforia的Unity3D开发,模型附上特效后大量报错
      • ¥35 Python实现文本关键词提取
      • ¥20 如何使用c++语言完成实验仪器管理系统
      • ¥15 请问Unity使用Magica Cloth插件怎么调整散兵的帘子和振袖比较好?