Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/13.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 如何将复杂字符串写入Gson类_Java_Json_Gson - Fatal编程技术网

Java 如何将复杂字符串写入Gson类

Java 如何将复杂字符串写入Gson类,java,json,gson,Java,Json,Gson,我一直在绞尽脑汁试图让POJO使用以下json字符串。我一直在做的一件事是在POJO中创建多个POJO,类似于spring boot中所需的POJO。不确定GSON是否也需要此功能。经过多次尝试,我仍然没有得到它。提前谢谢你的建议 Json字符串: "results": [ { "id": "superficial", "language": "en", "lexicalEntries": [

我一直在绞尽脑汁试图让POJO使用以下json字符串。我一直在做的一件事是在POJO中创建多个POJO,类似于spring boot中所需的POJO。不确定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"
        }
POJO:

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;
//
}
课程结果{
私有字符串id;
私有字符串语言;
私有字符串词典;
私有字符串类型;
私有字符串字;
//
}
类导数{
私有字符串id;
私有字符串文本;
//
}
班级条目{
私有字符串词源;
私有字符串语法特征;
私有int同形数字;
私人清单;
//
}
公共类词汇表{
私人衍生品;
私人名单条目;
私有字符串语言;
私有字符串词汇分类;
私人列表发音;
私有字符串文本;
//
}
公共类发音{
私家弦方言;
私有字符串注音法;
私有字符串拼音;
//
}
阶级意识{
私有字符串定义;
私有字符串示例;
私有字符串id;
私人短定义短定义;
私人名单子公司;
私有列表同义词表链接;
//
}
类简短定义{
私有字符串短_定义;
//
}
类子类{
私有字符串定义;
私有字符串域;
私有字符串示例;
私有字符串id;
私有字符串短定义;
私有字符串同义词表链接;
//
}
类叙词表链接{
私有字符串条目\u id;
私有字符串检测id;
//
}

我已根据您的JSON更正了您的POJO类定义

我建议您阅读JSON符号,了解不同的数据类型在其中的表示方式,如数组/列表、对象、字符串、int、布尔值。这将澄清您的理解,并且您将知道为什么您的类没有正确映射到JSON数据模式

课程结果{
私有字符串id;
私有字符串语言;
私有列表词典;
私有字符串类型;
私有字符串字;
//
}
公共类词汇库{
私人上市衍生品;
私人名单条目;
私有字符串语言;
私有字符串词汇分类;
私人列表发音;
私有字符串文本;
//
}
类导数{
私有字符串id;
私有字符串文本;
//
}
班级报名{
私人列表词源;
私有列表语法特征;
私有字符串homographNumber;//如果它在JSON中有引号,那么它将是一个字符串而不是int。JSON是一种强类型对象表示法
私人清单;
//
}
类语法特征{
字符串文本;
字符串类型;
}
公开课发音{
私有字符串音频文件;
私人列表方言;
私有字符串注音法;
私有字符串拼音;
//
}
阶级意识{
私人名单定义;
私人名单示例;
私有字符串id;
私有列表短_定义;
私人名单子公司;
私有列表同义词表链接;
//
}
课例{
字符串文本;
}
类次义{
私人名单定义;
私有列表域;
私人名单示例;
私有字符串id;
私人名单短定义;
私有列表同义词表链接;
//
}
类叙词表链接{
私有字符串条目\u id;
私有字符串检测id;
//
}

构建相应的类有什么问题吗?您好,我已经添加了我的类,但是我得到了一个空指针。我想我的课是错的。注意我有所有的二传手和传手。
class Results {

    private String id;
    private String language;
    private List<LexicalEntry> lexicalEntries;
    private String type;
    private String word;

//
}

public class LexicalEntry {

    private List<Derivative> derivatives;
    private List<Entry> entries;
    private String language;
    private String lexicalCategory;
    private List<Pronunciation> pronunciations;
    private String text;
//
}

class Derivative {

    private String id;
    private String text;
//
}


class Entry {

    private List<String> etymologies;
    private List<GrammaticalFeature> grammaticalFeatures;
    private String homographNumber; //if it has quotes in JSON, it will be a string not int..JSON is a strongly typed object notation
    private List<Sense> senses;
    //
}

class GrammaticalFeature{
    String text;
    String type;
}



public class Pronunciation {
    private String audioFile;
    private List<String> dialects;
    private String phoneticNotation;
    private String phoneticSpelling;
//
}

class Sense {

    private List<String> definitions;
    private List<Example> examples;
    private String id;
    private List<String> short_definitions;
    private List<Subsense> subsenses;
    private List<ThesaurusLinks> thesaurusLinks;
//

}

class Example{
    String text;
}

class Subsense {

    private List<String> definitions;
    private List<String> domains;
    private List<Example> examples;
    private String id;
    private List<String> shortDefinitions;
    private List<ThesaurusLink> thesaurusLinks;
//
}

class ThesaurusLink {
    private String entry_id;
    private String sense_id;
//
}