【转】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. nginx+uwsgi部署python web(web.py)

    1.nginx: nginx 是一个 http 服务器,与 apache.lighttpd.Microsoft IIS 等属于同类产品. 2.uWSGI: uWSGI 是一个快速的.纯C语言开发的.自 ...

  2. Sql日期时间格式转换 备用

    sql server2000中使用convert来取得datetime数据类型样式(全) 日期数据格式的处理,两个示例: CONVERT(varchar(16), 时间一, 20) 结果:2007-0 ...

  3. JS中的内存泄漏

    明天下午面试微店的前端开发职位,有点紧张~~ 刚刚正好看到js中的内存泄露,所以来整理一番. 给DOM对象添加的属性是对一个js对象的引用. var MyObject = {}; document.g ...

  4. css为网页顶部和底部都加入背景图

    网页背景图是我们常用的功能,一般来说.给网页加一个背景图,只要在网页的body标签中加入css属性就行. 代码如下:<body style="background-image:url( ...

  5. 新唐M0特点分析

    1,价格低,05x系列0.6-1.5美金,1xx系列1.5-3.5美金:2,性能好,最新32位CORTEX-M0的ARM核,唯一可工作到+5.5V的CORTEX-M0:3,速度快,CPU核能跑到50M ...

  6. Windows Azure 网站自愈

    编辑人员注释:本文章由 Windows Azure 网站团队的项目经理Apurva Joshi 撰写. 您有多少次在半夜被叫醒去解决一个仅需重新启动网站即可解决的问题?要是可以自动检测一些状况并自动恢 ...

  7. HDU 3307 Description has only two Sentences

    数学实在是差到不行了…… #include <cstdio> #include <cstring> #include <algorithm> #include &l ...

  8. 编译最新ffmpeg2.0.1到iOS设备

    www.mingjianhua.com 转载请注明出处. 上一篇文章讲了用NDKr9编译最新ffmpeg2.0.1到android平台,一般做了Android平台的编解码就免不了要做iOS,这次一起把 ...

  9. HDU 1104 Remainder( BFS(广度优先搜索))

    Remainder Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Sub ...

  10. 【剑指offer】调整数组顺序

    转载请注明出处:http://blog.csdn.net/ns_code/article/details/25829395 剑指offer上的第14题,九度OJ为了确保输出的结果的唯一性,在输出上做了 ...