doufeng9567 2016-06-11 14:32
浏览 773
已采纳

如何解析内部带有注释的JSON?

In go the standard package encoding/json exposes json.Unmarshal function to parse JSON.

I have a JSON like this:

{
    ...
    "tyo": {
        "ping_only": true,
        "addresses": [
            //"155.133.245.25:27015-27050",
            //"155.133.245.26:27015-27050",
            //"155.133.245.27:27015-27050",
            "45.121.186.20:27015-27016",
            "45.121.186.21:27015-27016"
        ]
    },
    "vie": {
        "addresses": [
            "185.25.182.225:27015-27050",
            "185.25.182.226:27015-27050"
        ]
    },
    ...
}

When I use json.Unmarshal I got error:

Handler crashed with error invalid character '/' looking for beginning of value

Can someone tell me how to parse this?

  • 写回答

3条回答 默认 最新

  • douyuan9512 2016-06-12 19:07
    关注

    Strict JSON specification, don't allow comments.

    But exist not-official superset of JSON that permits comments (and more other cool things), like JSON5 or HJSON (human-json).

    You can try with these Go libraries:

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100