You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

TCL json2dict使用报错求助:官方示例执行失败及修正验证

TCL json2dict 报错“missing value to go with key”的解决办法

参考TCL json库官方示例编写代码时,执行以下代码会触发missing value to go with key错误:

package require json
1.3.3

set data [::json::json2dict {
    "Image": {
        "Width":  800,
        "Height": 600,
        "Title":  "View from 15th Floor",
        "Thumbnail": {
            "Url":    "http://www.example.com/image/481989943",
            "Height": 125,
            "Width":  "100"
        },
        "IDs": [116, 943, 234, 38793]
    }
} ]

dict get $data Image
missing value to go with key

dict keys $data
missing value to go with key

解决办法

给传入::json::json2dict的JSON字符串外层额外添加一对大括号,修正后代码可正常运行:

set data [::json::json2dict {{
    "Image": {
        "Width":  800,
        "Height": 600,
        "Title":  "View from 15th Floor",
        "Thumbnail": {
            "Url":    "http://www.example.com/image/481989943",
            "Height": 125,
            "Width":  "100"
        },
        "IDs": [116, 943, 234, 38793]
    }
}} ]

内容的提问来源于stack exchange,提问作者Gert Gottschalk

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.15 13:42:15