[转]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.

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();
}
时间: 2024-10-03 00:14:07

[转]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 are 20 Jave code examples that show how to use the javax.servlet.http.Part class. These examples are extracted from open source projects. You can click 

Java Code Examples for io.netty.util.concurrent.GlobalEventExecutor

Example 1 Project: lettuce   File: FuturesTest.java View source code 6 votes @Test public void regularUse() throws Exception { final DefaultPromise<Boolean> target = new DefaultPromise<Boolean>(GlobalEventExecutor.INSTANCE); Futures.PromiseAgg

Java Code Examples for PhantomJSDriverService

Example 1 Project: thucydides   File: PhantomJSCapabilityEnhancer.java View source code Vote up 6 votes public void enhanceCapabilities(DesiredCapabilities capabilities) { if (environmentVariables.getProperty(ThucydidesSystemProperty.PHANTOMJS_BINARY

Java vs. Python (1): Simple Code Examples

Some developers have claimed that Python is more productive than Java. It is dangerous to make such a claim, because it may take several days to prove that thoroughly. From a high level view, Java is statically typed, which means all variable names h

【Android XML】Android XML 转 Java Code 系列

最近在公司做一个项目,需要把Android界面打包进jar包给客户使用.对绝大部分开发者来说,Android界面的布局以XML文件为主,并辅以少量Java代码进行动态调整.而打包进jar包的代码,意味着无法通过常规的getResources(),getString()等方法来快速的获取资源,因为这些资源都是在apk安装的时候初始化生成的.为了满足客户的需求,笔者开始在网上寻找各种解决方案.结果如下: 1.apk 主体包方案 实现方法:安装一个新的apk,新apk和主apk使用android:sh

Java类加载器及Android类加载器基础

引子 Android插件化与热更新技术日渐成熟,当你研究这些技术时会发现类加载器在其中占据重要地位.Java语言天生就有灵活性.动态性,支持运行期间动态组装程序,而这一切的基础就是类加载器. Java中的类加载器 Java灵活性和动态性的原因 Java源代码被编译器编译成字节码,即从.java文件编译为.class文件,而.class文件就是通过类加载器加载到虚拟机内存中的. 虚拟机的类加载(Class Loading)过程分为加载.链接(验证.准备.解析).初始化.使用.卸载等过程.这里仅考虑

HTMLPARSER JAVA CODE

1 /*** 2 * Licensed to the Apache Software Foundation (ASF) under one or more 3 * contributor license agreements. See the NOTICE file distributed with 4 * this work for additional information regarding copyright ownership. 5 * The ASF licenses this f

java的String和android的String有什么区别?

这是今天阿里电话面试被问到的,在之前确实没有想过(一直以为是一样的),于是面试完之后,我马上打开了源码,对这两个String类进行了比较,下面是我的发现. 首先我观察了这两个String类所导入的包,发现两者有些差异: 这是android版本: import java.io.Serializable; import java.io.UnsupportedEncodingException; import java.nio.ByteBuffer; import java.nio.CharBuffe

android用jsonReader来解析json

对于这个json: { "id" : "3232", "data" : [{ "data1" : "555", "data2" : "3243" }, { "data1" : "888", "data2" : "777" }] } 我们可以这样来解析: import java.io.IOE