zoukankan      html  css  js  c++  java
  • [转]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();
    }
     
  • 相关阅读:
    OSG-提示“error reading file e:1.jpg file not handled”
    OSG-加载地球文件报0x00000005错误,提示error reading file simple.earth file not handled
    QT-找开工程后,最上方提示the code model could not parse an included file, which might lead to incorrect code completion and highlighting, for example.
    我的书《Unity3D动作游戏开发实战》出版了
    java中无符号类型的第三方库jOOU
    Windows批处理备份mysql数据
    使用 DevTools 时,通用Mapper经常会出现 class x.x.A cannot be cast to x.x.A
    Java版本,Java版本MongoDB驱动,驱动与MongoDB数据库,Spring之间的兼容性
    Jrebel本地激活方法
    wget下载指定网站目录下的所有内容
  • 原文地址:https://www.cnblogs.com/howdop/p/5285853.html
Copyright © 2011-2022 走看看