如何解决json解析错误?

时间:2018-02-28 13:43:47

标签: javascript .net json parsing

我的问题很简单。但我想我无法实现下面的解析错误:(您可以使用https://jsonformatter.org/来获取错误)


{"lookup": "defaultStatelessKieSession",
    "commands": [
        "insert": {
            "object": {
                "myteam.hello_kie_server_2.SMS": {
                    "sendMessage" :  true
                }
            },
            "disconnected": false,
            "out-identifier": "Message",
            "return-object": true,
            "entry-point": "DEFAULT"
        },    
        { "fire-all-rules" :{} }


     ]
}

解析问题是:


Parse error on line 3:
... [
        "insert": {
            "ob
----------------------^
Expecting 'EOF', '}', ',', ']', got ':'

但我不明白哪个" {"或" ["。你可以帮帮我吗?

2 个答案:

答案 0 :(得分:1)

key-value对对象在数组中是无效的,因此您需要删除此部分"insert":

{
  "lookup": "defaultStatelessKieSession",
  "commands": [{
      "object": {
        "myteam.hello_kie_server_2.SMS": {
          "sendMessage": true
        }
      },
      "disconnected": false,
      "out-identifier": "Message",
      "return-object": true,
      "entry-point": "DEFAULT"
    },
    {
      "fire-all-rules": {}
    }
  ]
}

答案 1 :(得分:1)

元素“insert”是一个json对象,必须放入{}

{
    "lookup": "defaultStatelessKieSession",
    "commands": [
        {
            "insert": {
                "object": {
                    "myteam.hello_kie_server_2.SMS": {
                        "sendMessage": true
                    }
                },
                "disconnected": false,
                "out-identifier": "Message",
                "return-object": true,
                "entry-point": "DEFAULT"
            }
        },
        {
            "fire-all-rules": {}
        }
    ]
}