net.sf.json.JSONException: Object is null

This error occurs because when net.sf.json.JSONArray or JSONObject conversion, within the object contains another object, and the object that is included is NULL, it throws an exception. One solution is to remove the json string where the null, but feel a little tedious, after seeing fastjson can solve.

After fastjson data processing, comprising a null key-value pair is deleted in.

fastjson remove method replaces net.sf.json the discard method, remove method returns the output to see the data that seems to be removed, but will remove the return value into the group, when really remove the data corresponding to the original value data. . .

  for (int i = 0; i < sectionsArray.size(); i++) {
                JSONObject jsonObject = (JSONObject) sectionsArray.get(i);
                System.out.println("jsonObject: " + jsonObject);
                System.out.println("111:" + jsonObject.remove("contents") );
//               JSONObject jsonObject2 = (JSONObject) jsonObject.remove("contents");
//                JSONObject jsonObject2 = (JSONObject) jsonObject.discard("contents");
                jsonObject.remove("contents");
//                jsonArray1.add(jsonObject2);
                jsonArray1.add(jsonObject);

            }

 

So I wonder is my background data like this (with the json online analytical tool looks better (

[{ "Data structure Introduction": [{ "createUserId": 37, "submitTime": 1584147431000, "chapterId": 1, "sectionsName": "Data structure Introduction", "id": 1, "keyWord": "Data structure "}, {" createUserId ": 0," chapterId ": 1," sectionsName ":" algorithm data structure "," id ": 2," keyWord ":" algorithm data structure "}, {" createUserId ": 0 , "chapterId": 1, "sectionsName": "gradual data structure", "id": 3, "keyWord": "time complexity"}]}, { "array": [{ "createUserId": 0, "chapterId": 2, "sectionsName": "pointer", "id": 4, "keyWord": "pointer"}, { "createUserId": 0, "chapterId": 2, "sectionsName": "structure" , "id": 5, "keyWord": "structure"}]}, { "list": []}, { "Stack ": []}, {" Queue ": []}, {" tree ": []}, {" map ": []}, {" Find ": []}, {" Sorting ": [] }]

However, the spread to the front, this is indeed, as more number key values, processing proceeds when the front end of this way a lot of trouble. I do not know what's the solution.

  1. 0: {Profile Data Structure: Array (3)}
  2. 1: {Array: Array (2)}
  3. 2: {list: Array (0)}
  4. 3: {Stack: Array (0)}
  5. 4: {queue: Array (0)}
  6. 5: {Tree: Array (0)}
  7. 6: {FIG: Array (0)}
  8. 7: {Find: Array (0)}
  9. 8: {Sort: Array (0)}

 

 
Published 13 original articles · won praise 0 · Views 193

Guess you like

Origin blog.csdn.net/qq_24687915/article/details/104950214