[转]Java Code Examples for android.util.JsonReader
【转】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.
| 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();
}
| 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;
}
| 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的更多相关文章
- 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 ...
- 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 ...
- Java Code Examples for PhantomJSDriverService
Example 1 Project: thucydides File: PhantomJSCapabilityEnhancer.java View source code Vote up 6 vo ...
- Androidstudio预览时出现错误java.lang.NoClassDefFoundError: com/android/util/PropertiesMap
参考博客;http://blog.csdn.net/daqi1983/article/details/51474588 更改对应版本的SDK即可.
- Java Code Examples for org.springframework.http.HttpStatus
http://www.programcreek.com/java-api-examples/index.php?api=org.springframework.http.HttpStatus
- 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 ...
- 【Android XML】Android XML 转 Java Code 系列之 介绍(1)
最近在公司做一个项目,需要把Android界面打包进jar包给客户使用.对绝大部分开发者来说,Android界面的布局以XML文件为主,并辅以少量Java代码进行动态调整.而打包进jar包的代码,意味 ...
- 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 ...
- Java乔晓松-android中上传图片到服务器Tomcat(Struts2)
在做android开发的时候,有时你会用到图片的上传功能,在我的android项目中,我是选中图片,点击上传多张图片 android客户端上传图片部分的代码如下: package com.exampl ...
随机推荐
- c++ primer plus 习题答案(5)
p333.7 #include<iostream> #include<cstring> #include<cstdlib> using namespace std; ...
- gsoap 超时(timeout)设置
参考:http://www.cs.fsu.edu/~engelen/soapdoc2.html#tth_sEc19.19 gsoap就不用介绍了,是一个c/c++编写的可用于服务端与客户端的连接工具. ...
- 不小心中了machook病毒
此文运用的是优雅的Markdown而书 前段回家过年的日子,我心爱的小air在运行时不停的弹出"machook停止运行"的提醒,上网google一下不看不要紧,才得知是mac上的一 ...
- MyEclipse 在loading workbench 启动卡死
解决方法: 找到Workspace目录,在.metadata(Mac 下是在 .metadata/.plugins)中删掉以下两个文件 org.eclipse.ui.workbench org.ecl ...
- awk的用法(转)
awk 用法:awk ' pattern {action} ' 变量名 含义 ARGC 命令行变元个数 ARGV 命令行变元数组 FILENAME 当前输入文件名 FNR 当前文件中的记录号 FS 输 ...
- (Problem 42)Coded triangle numbers
The nth term of the sequence of triangle numbers is given by, tn = ½n(n+1); so the first ten triangl ...
- 帝国cms7.2自定义列表建立tag效果 代码 教程
统计记录:(如:select count(*) as total from phome_ecms_news where classid=1 and checked=1) 注:这句SQL的意思是查找统计 ...
- linux 的 ping 原理
ping命令的工作原理是: ping命令是用来查看网络上另一个主机系统的网络连接是否正常的一个工具. 他向网络上的另一个主机系统发送ICMP报文,如果指定系统得到了报文,它将把报文原样传回给发送者,这 ...
- JAVA GUI学习 - JProgressBar进度条组件摘录
public class JProgressBarTest extends JFrame{ public JProgressBarTest() { super(); setTitle("表格 ...
- Java学习之DBUtils工具的学习
简介 commons-dbutils 是 Apache 组织提供的一个开源 JDBC工具类库,它是对JDBC的简单封装,学习成本极低,并且使用dbutils能极大简化jdbc编码的工作量,同时也不会影 ...