Exemplo n.º 1
0
  public static Site parseSiteInfo(String json) throws JSONException {
    Site site = null;

    JSONObject siteInfoObject = new JSONObject(json);
    site = parseSite(siteInfoObject);

    JSONObject types = (JSONObject) siteInfoObject.get("guide-types");
    site.mGuideTypes = new ArrayList<GuideType>();

    Iterator<?> keys = types.keys();
    while (keys.hasNext()) {
      String key = (String) keys.next();
      if (types.get(key) instanceof JSONObject) {
        site.mGuideTypes.add(parseGuideType(key, (JSONObject) types.get(key)));
      }
    }

    return site;
  }
Exemplo n.º 2
0
  /** Reads through the given JSONObject and adds any topics to the given topic. */
  private static ArrayList<TopicNode> parseTopicChildren(JSONObject jTopic) throws JSONException {
    // Don't allocate any lists if it's empty.
    if (jTopic.length() == 0) {
      return null;
    }

    @SuppressWarnings("unchecked")
    Iterator<String> iterator = jTopic.keys();
    String topicName;
    ArrayList<TopicNode> topics = new ArrayList<TopicNode>();
    TopicNode currentTopic;

    while (iterator.hasNext()) {
      topicName = iterator.next();

      currentTopic = new TopicNode(topicName);
      currentTopic.setChildren(parseTopicChildren(jTopic.getJSONObject(topicName)));

      topics.add(currentTopic);
    }

    return topics;
  }