public static PebbleDictionary fromJson ( String jsonString ) throws JSONException { PebbleDictionary d = new PebbleDictionary ( ) ; JSONArray elements = new JSONArray ( jsonString ) ; for ( int idx = 0 ; idx < elements . length ( ) ; ++ idx ) { JSONObject o = elements . getJSONObject ( idx ) ; final int key = o . getInt ( KEY ) ; final PebbleTuple . TupleType type = PebbleTuple . TYPE_NAMES . get ( o . getString ( TYPE ) ) ; final PebbleTuple . Width width = PebbleTuple . WIDTH_MAP . get ( o . getInt ( LENGTH ) ) ; switch ( type ) { case BYTES : byte [ ] bytes = Base64 . decode ( o . getString ( VALUE ) , Base64 . NO_WRAP ) ; d . addBytes ( key , bytes ) ; break ; case STRING : d . addString ( key , o . getString ( VALUE ) ) ; break ; case INT : if ( width == PebbleTuple . Width . BYTE ) { d . addInt8 ( key , ( byte ) o . getInt ( VALUE ) ) ; } else if ( width == PebbleTuple . Width . SHORT ) { d . addInt16 ( key , ( short ) o . getInt ( VALUE ) ) ; } else if ( width == PebbleTuple . Width . WORD ) { d . addInt32 ( key , o . getInt ( VALUE ) ) ; } break ; case UINT : if ( width == PebbleTuple . Width . BYTE ) { d . addUint8 ( key , ( byte ) o . getInt ( VALUE ) ) ; } else if ( width == PebbleTuple . Width . SHORT ) { d . addUint16 ( key , ( short ) o . getInt ( VALUE ) ) ; } else if ( width == PebbleTuple . Width . WORD ) { d . addUint32 ( key , o . getInt ( VALUE ) ) ; } break ; } } return d ; }
Deserializes a JSON representation of a PebbleDictionary .