public static DataStore fromJson ( final JSONObject json ) throws ParseException { DataStore ret ; JSONArray jsonCols = json . getJSONArray ( "fields" ) ; if ( ! "time" . equals ( jsonCols . get ( 0 ) ) ) { throw new JSONException ( "time must be the first item in 'fields'" ) ; } Set < String > cols = new HashSet < String > ( ) ; for ( int i = 1 ; i < jsonCols . length ( ) ; i ++ ) { cols . add ( jsonCols . getString ( i ) ) ; } ret = new DataStore ( cols ) ; JSONArray jsonData = json . getJSONArray ( "data" ) ; for ( int i = 0 ; i < jsonData . length ( ) ; i ++ ) { JSONArray row = jsonData . getJSONArray ( i ) ; Long ts = row . getLong ( 0 ) ; Map < String , Object > vals = new HashMap < String , Object > ( ) ; for ( int j = 1 ; j < row . length ( ) ; j ++ ) { vals . put ( jsonCols . getString ( j ) , row . get ( j ) ) ; } ret . rows . put ( ts , vals ) ; } return ret ; }
Create a DataStore object from JSON .