简体   繁体   English

在Java中使用GSON解析JSON时出错

[英]Error parsing JSON with GSON in Java

I want to parse a JSON like this one: 我想解析这样的JSON:

{
"Header":{"S":"1A-01-07"},
"Items":{"L":[{"M":{"Name":{"S":"SL-1A Pre-Action (Green)"},"Roles":{"L":[{"S":"3cc3"}]}}},
            {"M":{"Name":{"S":"SL-8A Pre-Action (Yellow)"},"Roles":{"L":[{"S":"3cc3"}]}}}]
        }
}

and for that I created this class structure: 为此,我创建了这个类结构:

    public class CLI {

    Header Header;
    Items Items;

    public Header getHeader() {
        return Header;
    }
    public void setHeader(Header h) {
        Header = h;
    }
    public Items getItems() {
        return items;
    }
    public void setItems(Items i) {
        items = i;
    }

}

class Header {
    String S;

    public String getS() {
        return S;
    }

    public void setS(String s) {
        S = s;
    }
}

class Items {
    List<Map<Roles,Name>> L;

    public List<Map<Roles, Name>> getL() {
        return L;
    }

    public void setL(List<Map<Roles, Name>> l) {
        L = l;
    }
}

class Roles {
    List<Item1> itemList;

    public List<Item1> getLista() {
        return itemList;
    }

    public void setLista(List<Item1> l) {
        this.itemList = l;
    }
}

class Name {
    Item1 name;

    public Item1 getName() {
        return name;
    }

    public void setName(Item1 n) {
        this.name = n;
    }
}

class Item1 {
    String S;

    public String getS() {
        return S;
    }

    public void setS(String s) {
        S = s;
    }
}

but when I try to deserialize it with fromJson("myJSON", CLI.class) I get this error: "Unterminated object at line 1 column 80 path $.Items.[0]...". 但是,当我尝试使用fromJson(“ myJSON”,CLI.class)进行反序列化时,出现此错误:“第1行第80列$ .Items。[0] ...处的未终止对象”。 I've checked the structure a hundred times, but I don't see what could be wrong with it. 我已经对该结构进行了一百次检查,但是我看不出它有什么问题。

Could you help me find what the problem? 您能帮我找出问题所在吗?

Your json is incorrectly formatted, see http://www.w3schools.com/json/ for some examples but essentially no = 您的json格式不正确,请参见http://www.w3schools.com/json/了解一些示例,但实际上没有=

Try and google a json parser that will show the errors or use an addon for text editors such as Atom eg https://atom.io/packages/atom-beautify Which will auto format your json and show errors 尝试并在Google上搜索将显示错误的json解析器,或使用文本编辑器(例如Atom)的插件,例如https://atom.io/packages/atom-beautify,它将自动格式化json并显示错误

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM