0

I want to parse a JSON like this one:

{
"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]...". 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?

toofast
  • 33
  • 1
  • 1
  • 5

1 Answers1

1

Your json is incorrectly formatted, see http://www.w3schools.com/json/ for some examples but essentially no =

Try and google a json parser that will show the errors or use an addon for text editors such as Atom e.g. https://atom.io/packages/atom-beautify Which will auto format your json and show errors

Lomas
  • 36
  • 4
  • I reformatted the JSON as you suggested (I edited my first message with the new version) and according to a JSON tester it should be ok now. But it appears that my class structure also needs corrections: when I run the program, I get this error: "Expected BEGIN_OBJECT but was STRING at line 1 column 44 path $.Items.L[0]" – toofast Jun 02 '16 at 08:37
  • See: http://stackoverflow.com/questions/28418662/expected-begin-object-but-was-string-at-line-1-column-1 this should explain your error :) – M. Suurland Jun 02 '16 at 09:24