0
votes

I have code in BeanShell PostProcessor like this,

import org.json.simple.JSONObject;
import org.json.simple.JSONArray;
import org.json.simple.parser.JSONParser;
import java.util.*; 
String response = prev.getResponseDataAsString();
JSONParser parser = new JSONParser();
JSONArray GroupList = (JSONArray) parser.parse(response);
JSONArray GroupIds = new JSONArray();
while (i.hasNext()) 
{
JSONObject objGroup = (JSONObject) i.next();
  GroupIds.push(i.next().get("id"));
  var.put("GroupIds",GroupIds);
}

log.info(GroupIds);

When I try to run test, it show error,

jmeter.util.BeanShellInterpreter: Error invoking bsh method: eval Sourced file: inline evaluation of: ``import org.json.simple.JSONObject; import org.json.simple.JSONArray; import org. . . . '' : Attempt to resolve method: hasNext() on undefined variable or class name: i

jmeter.extractor.BeanShellPostProcessor: Problem in BeanShell script org.apache.jorphan.util.JMeterException: Error invoking bsh method: eval Sourced file: inline evaluation of: ``import org.json.simple.JSONObject; import org.json.simple.JSONArray; import org. . . . '' : Attempt to resolve method: hasNext() on undefined variable or class name: i

How can I correct this code ? thanks

1

1 Answers

1
votes

Your code is wrong , you have :

while (i.hasNext())

But i is not defined.

You should add something like this before the while:

Iterator i = GroupList.iterator();