这是我的 JSON 字符串
"[{"name":"3214657890RootSAPSSE","children":[{"name":"672BENIAMEEN .Sales Base Market SectionCustomer Representative"},{"name":"672BENIAMEEN .Sales Base Market SectionPeão"}]}]"
当我将它解析为 java 中的 json 对象时,我得到空值。此字段来自 HTML 隐藏字段,它来自 java 脚本。
这是我的java代码
String x = request.getParameter("JSONString");
System.out.println(x);
JSONArray jsonObject = (JSONArray) JSONValue.parse(x);
Gson gson = new Gson();
java.lang.reflect.Type type = new TypeToken<List<EmployeeJSONObj>>(){}.getType();
List<EmployeeJSONObj>l = gson.fromJson(jsonObject.toJSONString(), type);
System.out.println(l.get(0).getName());
这是我的Java类
public class EmployeeJSONObj {
private String name;
private List<EmployeeJSONObj> children = new LinkedList<>();
EmployeeJSONObj()
{
}
public String getName()
{
return name;
}
public String toString() {
return "name: " + name + ", children = " + children;
}
}