我在验证 json 字符串时遇到问题。我正在使用下面的代码
if jq -e . >/dev/null 2>&1 <<<"$json_string"; then
echo "Parsed JSON successfully and got something other than false/null"
else
echo "Failed to parse JSON, or got false/null"
fi
这不适用于json_string={"fruit":{"name":"app
. 这仍然成功显示解析的 JSON,并且得到了除 false/null 以外的其他内容,因为 json 字符串不完整。