net.sf.json.JSONObject
- 2020-06-07 04:29:58
- OfStack
When doing a project, I encountered such a pit: How to judge whether json on 1 is empty,
The starting code looks like this:
JSONObject detail = JSONObject.fromObject("123");
if (detail == null)
{
detail = new JSONObject();
}
No matter how you adjust the contents of the string, new Jsonobject() will not be taken. All kinds of try, all kinds of ask, finally no way, take detail method 1 each try, only to find that there is isNullObject() such a method, then have the following code,
JSONObject detail = JSONObject.fromObject("123");
if (detail == null || detail.isNullObject())
{
detail = new JSONObject();
}
All kinds of pits have been trodden on for so long, and there will be pits in the future. Solutions:
1. Look for similar problems on the Internet;
2. As in today's case, a class may already have available methods.
Colleagues are very good teachers. Ask a lot and face is the least valuable here.