如何在 GWT 中读取 Json 文件?

How To Read Json File in GWT?

{  
    "employee": {  
        "name":     "sachin",   
        "salary":      56000,     
    }       
}

这是我的 json 文件。 现在我只想读它。

当我写最后一行时,它给了我 NullPointerException

JSONValue value = JSONParser.parseLenient(json);
JSONObject employeeObject = value.isObject();
System.out.println(employeeObject.get("name").isString().stringValue());

应该是:

JSONValue value = JSONParser.parseStrict(json);
JSONObject employeeObject = (JSONObject) value.isObject().get("employee");

目前您没有评估对象 "employee" - 您正在评估 json 对象,该对象有一个 "employee" 对象作为其唯一的子对象。