这些 java 类 是否具有从 JSON 文件映射的正确结构?
Do these java classes have correct structures to map from a JSON file?
我正在将 JSON
文件解析为来自特定 URL 的 java 代码。看起来很容易。但是,由于某些原因,服务器对我将在下面显示的一些 键值 响应 null
。我很确定这些结构有问题(在 java 方面)。
这是 json 结构。
这里是代码(已经提供了 getters-setters 我只是不展示它们以使其清楚)
class JSON {
List<Result> result;
}
class Results{
String gender;
Name name;
Location location
}
class Name{
String title;
String first;
String last;
}
class Location {
String city;
String state;
String country;
String postcode;
}
我不确定我到底错过了什么。那些 类 相对于 JSON 结构是否具有正确的结构?
您似乎需要 results
而不是 JSON class
中的 result
我看到你的 Java Class 和 JSON 对象位置中的响应没有内部对象街道。
我看到一个问题,
字符串邮政编码似乎是上面JSON中的数字。
问题是用户定义的 class 引用 null
试试这个并创建 HAS-A 对 Object 的引用
使用 constructor()
初始化对象
class JSON {
List<Result> result;
public JSON(){
result = new ArrayList()
}
}
class Results{
String gender;
Name name;
Location location
public Results(){
Name = new Name();
Location = new Location();
}
}
class Name{
String title;
String first;
String last;
}
class Location {
String city;
String state;
String country;
String postcode;
}
我正在将 JSON
文件解析为来自特定 URL 的 java 代码。看起来很容易。但是,由于某些原因,服务器对我将在下面显示的一些 键值 响应 null
。我很确定这些结构有问题(在 java 方面)。
这是 json 结构。
这里是代码(已经提供了 getters-setters 我只是不展示它们以使其清楚)
class JSON {
List<Result> result;
}
class Results{
String gender;
Name name;
Location location
}
class Name{
String title;
String first;
String last;
}
class Location {
String city;
String state;
String country;
String postcode;
}
我不确定我到底错过了什么。那些 类 相对于 JSON 结构是否具有正确的结构?
您似乎需要 results
而不是 JSON class
result
我看到你的 Java Class 和 JSON 对象位置中的响应没有内部对象街道。
我看到一个问题,
字符串邮政编码似乎是上面JSON中的数字。
问题是用户定义的 class 引用 null
试试这个并创建 HAS-A 对 Object 的引用
使用 constructor()
class JSON {
List<Result> result;
public JSON(){
result = new ArrayList()
}
}
class Results{
String gender;
Name name;
Location location
public Results(){
Name = new Name();
Location = new Location();
}
}
class Name{
String title;
String first;
String last;
}
class Location {
String city;
String state;
String country;
String postcode;
}