Code example for JSONTokener

Methods: nextValue

0
        InstacartDataSource dataSource = new InstacartDataSource(mContext);
        dataSource.open();
        String decodedJSONString = null;
        try { 
            decodedJSONString = URLDecoder.decode(result, "utf-8");
            JSONTokener tokener = new JSONTokener(decodedJSONString);
            JSONObject object = (JSONObject) tokener.nextValue();
            JSONObject dataObject = object.getJSONObject("data");
            String user_access_token = dataObject.getString("access_token");
            dataSource.createUser(user_access_token);
            Log.i("access token stored for user:", "show main store window for user with token " + user_access_token);
 
            Intent newIntent = new Intent(mContext, StoreRootFragment.class);
            newIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            mContext.startActivity(newIntent);
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
        } catch (JSONException e) {
            e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
        } finally { 
            dataSource.close();