当一个String类型,解析成Json后,有可能是JsonObjec有可能是JsonArray怎么办?
例如json为这样的,可以调用JSONObject jsonObject = JSONObject.parseObject(str);转成JSONObject
{
"hoscode":"1000_0",
"depcode":"200040878",
"workDate":"2020-12-13",
"workTime":0,
"reservedNumber":33,
"availableNumber":22,
"amount":"100",
"status":1,
"hosScheduleId":"1"
}
但是有可能是对象的
[
{
"hoscode":"1000_0",
"depcode":"200040878",
"workDate":"2020-12-13",
"workTime":0,
"reservedNumber":33,
"availableNumber":22,
"amount":"100",
"status":1,
"hosScheduleId":"1"
},
{
"hoscode":"1000_0",
"depcode":"200040878",
"workDate":"2020-12-22",
"workTime":0,
"reservedNumber":40,
"availableNumber":6,
"amount":"100",
"status":1,
"hosScheduleId":"2"
}
]
这样需要调用,JSONArray jsonArray = JSONObject.parseArray(str);转成的就是JSONArray
但是str传递的不知道是啥,这样应该怎么处理?