Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/304.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/api/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 带有Setter/Getter的JSON_Java_Json_Selenium Webdriver_Getter Setter - Fatal编程技术网

Java 带有Setter/Getter的JSON

Java 带有Setter/Getter的JSON,java,json,selenium-webdriver,getter-setter,Java,Json,Selenium Webdriver,Getter Setter,在Selenium中,我使用JSON文件获取数据并将其传递到某些私有变量的Getter方法中,但它抛出了一个错误org.openqa.Selenium.WebDriverException:未知错误:键应该是字符串 以下是代码行: public class ABC { private String systemName; JSONObject jsonObj = null; public ABC() { File filePath = new File

在Selenium中,我使用JSON文件获取数据并将其传递到某些私有变量的Getter方法中,但它抛出了一个错误
org.openqa.Selenium.WebDriverException:未知错误:键应该是字符串

以下是代码行:

public class ABC {
    private String systemName;
    JSONObject jsonObj = null;

    public ABC() {
         File filePath = new File(filename);
         FileReader reader = null;
         try {
             reader = new FileReader(filename);
             JSONParser jsonParser = new JSONParser();
             JSONObject jsonObject = (JSONObject) jsonParser.parse(reader);
             jsonObj = jsonObject;
         } catch (FileNotFoundException e) {
             e.printStackTrace();
         } catch (ParseException e) {
             e.printStackTrace();
         }
    }

    public String getSystemName() {
        return (String) jsonObj.get("SystemName");
    }
}

public class DEF {
    ABC abc = new ABC();
    String testString = abc.getSystemName();
}
这里,
testString
的值设置为
null

(所有必需的包都已导入)

“您试图解析的JSON是什么?”您到底想知道什么?jsonObj.get返回什么?它是一个物体。您可以尝试使用
jsonObj.get(“SystemName”).toString()吗
或者你也可以使用
getString(key)
方法来获得所需的值。