【转】Java Code Examples for android.util.JsonReader

The following are top voted examples for showing how to use android.util.JsonReader. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to product more good examples.

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(new Exercise());
reader.beginArray();
for (int j = 0; reader.hasNext(); j++) {
this.exerciseList.get(i).exerciseUnits.add(new ArrayList<Integer>());
reader.beginArray();
while (reader.hasNext()) {
this.exerciseList.get(i).exerciseUnits.get(j).add(reader.nextInt());
}
reader.endArray();
}
reader.endArray();
}
reader.endArray();
break;
case "answerList":
reader.beginArray();
while (reader.hasNext()) {
this.answerList.add(reader.nextString());
}
reader.endArray();
break;
default:
reader.skipValue();
break;
}
}
reader.endObject();
reader.close();
}
 
 

[转]Java Code Examples for android.util.JsonReader的更多相关文章

  1. Java Code Examples for javax.servlet.http.Part

    http://www.programcreek.com/java-api-examples/index.php?api=javax.servlet.http.Part The following ar ...

  2. Java Code Examples for org.codehaus.jackson.map.DeserializationConfig 配置

    The following code examples are extracted from open source projects. You can click  to vote up the e ...

  3. Java Code Examples for PhantomJSDriverService

    Example 1 Project: thucydides   File: PhantomJSCapabilityEnhancer.java View source code Vote up 6 vo ...

  4. Androidstudio预览时出现错误java.lang.NoClassDefFoundError: com/android/util/PropertiesMap

    参考博客;http://blog.csdn.net/daqi1983/article/details/51474588 更改对应版本的SDK即可.

  5. Java Code Examples for org.springframework.http.HttpStatus

    http://www.programcreek.com/java-api-examples/index.php?api=org.springframework.http.HttpStatus

  6. Java Code Examples for org.apache.ibatis.annotations.Insert

    http://www.programcreek.com/java-api-examples/index.php?api=org.apache.ibatis.annotations.Insert htt ...

  7. 【Android XML】Android XML 转 Java Code 系列之 介绍(1)

    最近在公司做一个项目,需要把Android界面打包进jar包给客户使用.对绝大部分开发者来说,Android界面的布局以XML文件为主,并辅以少量Java代码进行动态调整.而打包进jar包的代码,意味 ...

  8. Caused by: java.lang.NoSuchMethodException: <init> [class android.content.Context, interface android.util.AttributeSet] 异常

    1. 异常描述 FATAL EXCEPTION: main Process: com.whereru.greengrass.goforit, PID: 13847 java.lang.RuntimeE ...

  9. Java乔晓松-android中上传图片到服务器Tomcat(Struts2)

    在做android开发的时候,有时你会用到图片的上传功能,在我的android项目中,我是选中图片,点击上传多张图片 android客户端上传图片部分的代码如下: package com.exampl ...

随机推荐

  1. ExtJS002Window创建

    Ext.onReady(function () { Ext.create('Ext.window.Window', { title: 'window', width: 400, height: 300 ...

  2. Windows上右键git菜单出来的原因

    Windows上右键git菜单出来的原因 Git下载地址https://code.google.com/p/msysgit/downloads/list?q=full+installer+offici ...

  3. Java反射的小故事

    Java反射的小故事: 首先定义一个Java类 package com.xiaoysec.test; public class Person { private String name; privat ...

  4. 经典阅读-《Effective C++》Item1:视C++为一个联邦语言

    C++已经是个多重范型编程语言(multiparadigm programming language),一个同时支持过程形式(procedural).面向对象形式(object-oriented).泛 ...

  5. Eclipse+ADT的环境搭建

    Index: . Java环境变量的设置 . Android环境变量的设置 1.Java环境变量的设置 A.属性名称:JAVA_HOME 属性值:C:\Program Files\Java\jdk1. ...

  6. 禁用Java DNS缓存-Disable DNS caching

    Once an application has performed network access (i.e. urlconnection, parsing of xml document with e ...

  7. QT 子窗口监听主窗口信号(超级简单,但是好用,比如主窗口移动的时候,子窗口不要再继续处理任务)

    MainWindow *ptr = NULL; ptr = (MainWindow*)parentWidget(); connect(ptr, SIGNAL(param_result(bool)), ...

  8. javascript 变量 命名规范 变量的作用域

    原文:javascript 变量 命名规范 变量的作用域 大家好,我是小强老师,今天讲解的是变量 变量 小时候我们学过  这个 应用题 :  X+1=2; 问  X 等于几?  答案是 1 对了,很聪 ...

  9. Boyer–Moore (BM)字符串搜索算法

    在计算机科学里,Boyer-Moore字符串搜索算法是一种非常高效的字符串搜索算法.它由Bob Boyer和J Strother Moore设计于1977年.此算法仅对搜索目标字符串(关键字)进行预处 ...

  10. haproxy 超时机制

    <pre name="code" class="python">option redispatch option redispatch 是否允许重新 ...