Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有以下 JSON 结构。
{ "activeInd":"1" }
我在插入 DTO 对象时将字符串转换为布尔值
setDTOActiveInd(request.getActiveInd() == "1")
当我验证表格时,它的 ActiveInd 为“0”,这是错误的
我的测试用例在发送“1”并从表中检索 true 但不确定为什么它不能将 JSON 中的“1”转换为布尔值“true”时通过了?
布尔值不是整数;1 和 0 在 Code 中不是布尔值。您需要明确地转换它们:
boolean activeInd= (1 == jsonObject.getInt("activeInd"));