【发布时间】:2018-07-08 16:39:30
【问题描述】:
我一直在绞尽脑汁试图让 pojos 使用以下 json 字符串。我一直在做的一件事是在 pojo 中制作多个 pojo,类似于在 spring boot 中所必需的。不确定 GSON 是否也需要这样做。经过多次尝试,我仍然没有得到它。感谢您提前提供任何建议。
Json 字符串:
"results": [
{
"id": "superficial",
"language": "en",
"lexicalEntries": [
{
"derivatives": [
{
"id": "superficialness",
"text": "superficialness"
}
],
"entries": [
{
"etymologies": [
"late Middle English: from late Latin superficialis, from Latin superficies (see superficies)"
],
"grammaticalFeatures": [
{
"text": "Positive",
"type": "Degree"
}
],
"homographNumber": "000",
"senses": [
{
"definitions": [
"existing or occurring at or on the surface"
],
"examples": [
{
"text": "the building suffered only superficial damage"
}
],
"id": "m_en_gbus1014360.017",
"short_definitions": [
"existing or occurring at or on surface"
],
"subsenses": [
{
"definitions": [
"situated or occurring on the skin or immediately beneath it"
],
"domains": [
"Anatomy",
"Medicine"
],
"examples": [
{
"text": "the superficial muscle groups"
}
],
"id": "m_en_gbus1014360.019",
"short_definitions": [
"situated or occurring on skin or immediately beneath it"
]
},
{
"definitions": [
"appearing to be true or real only until examined more closely"
],
"examples": [
{
"text": "the resemblance between the breeds is superficial"
}
],
"id": "m_en_gbus1014360.020",
"short_definitions": [
"appearing to be true or real only until examined more closely"
],
"thesaurusLinks": [
{
"entry_id": "superficial",
"sense_id": "t_en_gb0014419.004"
}
]
},
{
"definitions": [
"not thorough, deep, or complete; cursory"
],
"examples": [
{
"text": "he had only the most superficial knowledge of foreign countries"
}
],
"id": "m_en_gbus1014360.021",
"short_definitions": [
"not thorough or complete"
],
"thesaurusLinks": [
{
"entry_id": "superficial",
"sense_id": "t_en_gb0014419.003"
}
]
},
{
"definitions": [
"not having or showing any depth of character or understanding"
],
"examples": [
{
"text": "perhaps I was a superficial person"
}
],
"id": "m_en_gbus1014360.022",
"short_definitions": [
"not having or showing any depth of character or understanding"
],
"thesaurusLinks": [
{
"entry_id": "superficial",
"sense_id": "t_en_gb0014419.006"
},
{
"entry_id": "superficial",
"sense_id": "t_en_gb0014419.002"
}
]
}
],
"thesaurusLinks": [
{
"entry_id": "superficial",
"sense_id": "t_en_gb0014419.001"
}
]
}
]
}
],
"language": "en",
"lexicalCategory": "Adjective",
"pronunciations": [
{
"dialects": [
"American English"
],
"phoneticNotation": "respell",
"phoneticSpelling": "ˌso͞opərˈfiSHəl"
},
{
"audioFile": "http://audio.oxforddictionaries.com/en/mp3/superficial_us_1.mp3",
"dialects": [
"American English"
],
"phoneticNotation": "IPA",
"phoneticSpelling": "ˌsupərˈfɪʃəl"
}
],
"text": "superficial"
}
],
"type": "headword",
"word": "superficial"
}
Pojos:
class Results {
private String id;
private String language;
private String lexicalEntries;
private String type;
private String word;
//
}
class Derivatives {
private String id;
private String text;
//
}
class Entries {
private String etymologies;
private String grammaticalFeatures;
private int homographNumber;
private List<String> senses;
//
}
public class LexicalEntries {
private Derivatives derivatives;
private List<Entries> entries;
private String language;
private String lexicalCategory;
private List<Pronunciations> pronunciations;
private String text;
//
}
public class Pronunciations {
private String dialects;
private String phoneticNotation;
private String phoneticSpelling;
//
}
class Senses {
private String definitions;
private String examples;
private String id;
private ShortDefinitions short_definitions;
private List<Subsenses> subsenses;
private List<ThesaurusLinks> thesaurusLinks;
//
}
class ShortDefinitions {
private String short_definitions;
//
}
class Subsenses {
private String definitions;
private String domains;
private String examples;
private String id;
private String shortDefinitions;
private String thesaurusLinks;
//
}
class ThesaurusLinks {
private String entry_id;
private String sense_id;
//
}
【问题讨论】:
-
构建对应的类有什么问题?
-
您好,我已经添加了我的类,但我得到了一个空指针。我假设我的课程是错误的。注意我有所有的 setter 和 getter。