Example 1
Project: Earmouse File: ModuleStats.java View source code | 7 votes |
/**
* Reads an existing ModuleStats instance from a JSON file
* @param fr The FileReader to read from
* @throws IOException
*/
private void initModuleStatsFromJson(FileReader fr) throws IOException {
JsonReader reader = new JsonReader(fr);
reader.beginArray();
while (reader.hasNext()) {
reader.beginObject();
int exerciseIndex = -1;
boolean result = true;
long timestamp = -1;
while (reader.hasNext()){
String name = reader.nextName();
switch (name) {
case "exerciseIndex":
exerciseIndex = reader.nextInt();
break;
case "result":
result = reader.nextBoolean();
break;
case "timestamp":
timestamp = reader.nextLong();
break;
default:
reader.skipValue();
break;
}
}
moduleAnswerList.add(new ModuleAnswer(exerciseIndex, result, timestamp));
reader.endObject();
}
reader.endArray();
reader.close();
}
Example 2
Project: deck_old File: CardHolder.java View source code | Vote up | 6 votes |
public static CardHolder readFromJson( JsonReader reader ) throws IOException
{
CardHolder player = new CardHolder();
reader.beginObject();
while( reader.hasNext() )
{
String name = reader.nextName();
if( name.equals( JSON_ID ) )
{
player.mID = reader.nextString();
}
else if( name.equals( JSON_NAME ) )
{
player.mName = reader.nextString();
}
else if( name.equals( JSON_CARDS ) && reader.peek() != JsonToken.NULL )
{
reader.beginArray();
while( reader.hasNext() )
{
player.addCard( Card.readFromJson( reader ) );
}
reader.endArray();
}
else
{
reader.skipValue();
}
}
reader.endObject();
return player;
}
Example 3
Project: Earmouse File: Module.java View source code | Vote up | 5 votes |
/**
* Loads this Module‘s properties and data from the JSON data of the given Reader
* @param r The Reader from which to read the JSON data
* @throws IOException
*/
private void initModuleFromJson(Reader r) throws IOException {
JsonReader reader = new JsonReader(r);
reader.beginObject();
while (reader.hasNext()) {
String name = reader.nextName();
switch (name) {
case "moduleId":
this.id = reader.nextInt();
break;
case "title":
this.title = reader.nextString();
break;
case "description":
this.description = reader.nextString();
break;
case "shortDescription":
this.shortDescription = reader.nextString();
break;
case "lowestNote":
this.lowestNote = reader.nextInt();
break;
case "highestNote":
this.highestNote = reader.nextInt();
break;
case "difficulty":
this.difficulty = reader.nextInt();
break;
case "version":
this.toolVersion = reader.nextString();
break;
case "moduleVersion":
this.moduleVersion = reader.nextInt();
break;
case "exerciseList":
reader.beginArray();
for (int i = 0; reader.hasNext(); i++) {
this.exerciseList.add(