private void init(JSONObject json) throws TwitterException { id = ParseUtil.getLong("id", json); name = ParseUtil.getRawString("name", json); fullName = ParseUtil.getRawString("full_name", json); slug = ParseUtil.getRawString("slug", json); description = ParseUtil.getRawString("description", json); subscriberCount = ParseUtil.getInt("subscriber_count", json); memberCount = ParseUtil.getInt("member_count", json); uri = ParseUtil.getRawString("uri", json); mode = "public".equals(ParseUtil.getRawString("mode", json)); following = ParseUtil.getBoolean("following", json); createdAt = ParseUtil.getDate("created_at", json); try { if (!json.isNull("user")) { user = new UserJSONImpl(json.getJSONObject("user")); } } catch (JSONException jsone) { throw new TwitterException(jsone.getMessage() + ":" + json.toString(), jsone); } }
/** * Read recursively the JSON object in order to parse the content. * * @param jsonObj JSON object. * @param data Holds the parsed data. * @return Parsed data. * @throws ParserException If there is an error in the document format. */ protected Hashtable readJSON(JSONObject jsonObj, Hashtable data) throws ParserException { Enumeration keys = jsonObj.keys(); // while (keys.hasMoreElements()) { String key = keys.nextElement().toString(); // if (isMember(jsonObj, key)) { data.put(key, readJSON(jsonObj.getJSONObject(key), new Hashtable())); } else if (isArray(jsonObj, key)) { JSONArray array = jsonObj.getJSONArray(key); Hashtable[] arrayObj = new Hashtable[array.length()]; // for (int i = 0; i < arrayObj.length; i++) { arrayObj[i] = readJSON(array.getJSONObject(i), new Hashtable()); } // data.put(key, arrayObj); } else { data.put(key, jsonObj.getString(key)); } } // return data; }
public void ProcessAnswer(int type, String result) { System.out.println("-----ProcessAnswer"); System.out.println("-----type = "); System.out.println("-----result = " + result); switch (type) { case REQUEST_SESSION: { try { JSONObject jsonResponse = new JSONObject(result); JSONObject jsonSessionItem = jsonResponse.getJSONObject("session"); TOKEN = jsonSessionItem.getString("token"); System.out.println("-----TOKEN = " + TOKEN); doRequest(REQUEST_SIGN_UP_USER); } catch (Exception ex) { DebugStorage.getInstance() .Log(0, "<PushAuthScreen> ProcessAnswer REQUEST_SESSION ", ex); onClose(); } break; } case REQUEST_SIGN_UP_USER: { System.out.println("-----<ProcessAnswer> REQUEST_SIGN_UP_USER"); try { doRequest(REQUEST_SESSION_WITH_USER_AND_DEVICE_PARAMS); } catch (Exception ex) { DebugStorage.getInstance() .Log(0, "<PushAuthScreen> ProcessAnswer REQUEST_SIGN_UP_USER ", ex); } break; } case REQUEST_SESSION_WITH_USER_AND_DEVICE_PARAMS: { try { JSONObject jsonResponse = new JSONObject(result); JSONObject jsonSessionItem = jsonResponse.getJSONObject("session"); TOKEN = jsonSessionItem.getString("token"); System.out.println("----- TOKEN for get push token = " + TOKEN); doRequest(REQUEST_PUSH_TOKEN); } catch (Exception ex) { DebugStorage.getInstance() .Log(0, "<PushAuthScreen> ProcessAnswer REQUEST_SESSION ", ex); onClose(); } break; } case REQUEST_PUSH_TOKEN: { try { System.out.println("-----<ProcessAnswer> REQUEST_PUSH_TOKEN"); doRequest(REQUEST_PUSH_SUBSCRIBE); } catch (Exception ex) { DebugStorage.getInstance() .Log(0, "<PushAuthScreen> ProcessAnswer REQUEST_PUSH_SUBSCRIBE Exception ", ex); onClose(); } break; } case REQUEST_PUSH_SUBSCRIBE: { try { System.out.println("-----<ProcessAnswer> REQUEST_PUSH_SUBSCRIBE"); // doRequest(REQUEST_PUSH_SUBSCRIBE); } catch (Exception ex) { DebugStorage.getInstance() .Log(0, "<PushAuthScreen> ProcessAnswer REQUEST_PUSH_SUBSCRIBE Exception ", ex); onClose(); } break; } default: break; } }
/** @see com.twitterapime.parser.JSONHandler#handle(com.twitterapime.parser.JSONObject) */ public void handle(JSONObject jsonObj) throws ParserException { content = readJSON(jsonObj.getJSONObject(startKey), new Hashtable()); }