I'm trying to write a JSon document and its relative xsd file in order to generate JAXB classes and I don't think if I'm doing it in the right way. what I want is a structure like this:
team
-name="name"
-game="game"
-intarray
int
int
...
int
-values
[int1, int2]
[int1, int2]
...
[int1, int2]
-stringarrays
[string1, string2,...., stringn]
[string1, string2,...., stringn]
...
[string1, string2,...., stringn]
so I wrote my xsd and a example string in the json file to attempt to read it
example line:
{"name": "Team 1", "game": "game", "intarray": [1, 2, 3, 4, 5, 6], "values": [[10,20], [10,80], [10,30], [10,60], [10,50], [10,30]], "stringarrays": [["Azione", "Azione"], ["Azione", "Azione"], ["Azione", "Azione"], ["Azione", "Azione"], ["Azione", "Azione"], ["Azione", "Azione"]]}
and this is my xsd
<?xml version="1.0" encoding="UTF-8"?>
<schema xmlns="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.example.org/teams" xmlns:tns="http://www.example.org/teams" elementFormDefault="qualified">
<element name="team_list" type="tns:lista_team"></element>
<complexType name="team">
<sequence>
<element name="name" type="string"></element>
<element name="game" type="string"></element>
<element name="intarray" type="int" maxOccurs="unbounded"
minOccurs="0">
</element>
<element name="values" type="tns:ivev"></element>
<element name="stringarrays" type="tns:arrays"></element>
</sequence>
</complexType>
<complexType name="ivev">
<sequence>
<element name="couple" type="tns:ivev_couple" maxOccurs="unbounded" minOccurs="0"></element>
</sequence>
</complexType>
<complexType name="ivev_couple">
<sequence>
<element name="ivev_element" type="int" maxOccurs="unbounded" minOccurs="1"></element>
</sequence>
</complexType>
<complexType name="moveset">
<sequence>
<element name="mosse" type="string" maxOccurs="unbounded" minOccurs="0"></element>
</sequence>
</complexType>
<complexType name="arrays">
<sequence>
<element name="stringarray" type="tns:moveset" maxOccurs="unbounded" minOccurs="0"></element>
</sequence>
</complexType>
<complexType name="lista_team">
<sequence>
<element name="squadra" type="tns:team" maxOccurs="unbounded" minOccurs="0"></element>
</sequence>
</complexType>
eclipse keeps telling me that I have a MalformedJson, i think the problem is with the json line, i think that the xsd is almost correct, but i could be wrong :)
The code that writes the JSON document looks like this:
Gson gson = new Gson();
String json = gson.toJson(team);
try
{
FileWriter gwriter = new FileWriter("c:\\file.json");
gwriter.write(json);
gwriter.close();
}
catch(Exception e)
{
}
Which produces this JSON document:
{
"nome":"team1",
"game":"game",
"intarray":[1,2],
"arrayofintarrays":{
"couple":[]
},
"arrayofstringarrays":{
"mossearray":[]
}
}
This JSON document is then read with like this:
Team[] teams_loaded= null;
try
{
Reader reader = new InputStreamReader(DexLoader.class.getClassLoader().getResourceAsStream("teams.txt"));
Gson gson = new GsonBuilder().create();
JsonReader read = new JsonReader(reader);
teams_loaded = gson.fromJson(read, Team[].class);
}
catch(Exception c)
{
c.printStackTrace();
}
thanks!