0

I got error NullPointerException in Java.

I am just using JSONParser

String test is

{
    "processGroupRevision": {
        "clientId":"f98f0e63-0164-1000-6c10-442b4b1fbe8f",
        "version":1
        },
        "variableRegistry":{
            "variables": [{
                "variable": {
                    "name":"123123123",
                    "value":"12322",
                    "pr": "..." 
                }
            }]
        }
}

And here is the main Code

String test = sb.toString();
System.out.println(test);

JSONParser jsonParser = new JSONParser();
JSONObject jsonObj = (JSONObject) jsonParser.parse(test);
JSONArray jsonArray = (JSONArray) jsonObj.get("variable");

System.out.println("==================");

for (int i=0; i<jsonArray.size(); i++) {
    JSONObject tempObj = (JSONObject) jsonArray.get(i);
    System.out.println(""+(i+1)+" key : " + tempObj.get("name"));
    System.out.println(""+(i+1)+" value : " + tempObj.get("value"));
}

How can I fix this problem? Is it in the For loop ?

François Maturel
  • 5,884
  • 6
  • 45
  • 50
ko_ma
  • 911
  • 2
  • 11
  • 26

0 Answers0