Java Code Examples for org.json.JSONArray#optJSONObject()

The following examples show how to use org.json.JSONArray#optJSONObject() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AssetsActivity.java    From smartcoins-wallet with MIT License 6 votes vote down vote up
HashMap<String, ArrayList<String>> returnParseArray(String Json, String req) {
    try {
        JSONArray myArray = new JSONArray(Json);
        ArrayList<String> array = new ArrayList<>();
        HashMap<String, ArrayList<String>> pairs = new HashMap<String, ArrayList<String>>();
        for (int i = 0; i < myArray.length(); i++) {
            JSONObject j = myArray.optJSONObject(i);
            Iterator it = j.keys();
            while (it.hasNext()) {
                String n = (String) it.next();
                if (n.equals(req)) {
                    array.add(j.getString(n));
                    pairs.put(req, array);
                }
            }

        }
        return pairs;
    } catch (Exception e) {

    }
    return null;
}
 
Example 2
Source File: RippleDataApi.java    From RipplePower with Apache License 2.0 6 votes vote down vote up
public static ArrayList<String> reportsPaysAccounts(String date, int limit) {
	ArrayList<String> list = new ArrayList<String>(limit);
	String link = DATA_URL + "/v2/reports/" + date + "?accounts=true&payments=true&limit=" + limit;
	String result = open(link);
	if (result != null) {
		JSONObject obj = new JSONObject(result);
		JSONArray arrays = obj.optJSONArray("reports");
		int size = arrays.length();
		if (arrays != null && size > 0) {
			for (int i = 0; i < size; i++) {
				JSONObject report = arrays.optJSONObject(i);
				String account = report.optString("account");
				list.add(account);
			}
		}
	}
	return list;
}
 
Example 3
Source File: BackupImportChooserActivity.java    From FreezeYou with Apache License 2.0 6 votes vote down vote up
private void generateInstallPkgsAutoAllowPkgsList(JSONObject jsonObject, ArrayList<HashMap<String, String>> list) {
    JSONArray array = jsonObject.optJSONArray("installPkgs_autoAllowPkgs_allows");
    if (array == null) {
        return;
    }

    JSONObject jObj = array.optJSONObject(0);
    if (jObj == null) {
        return;
    }

    HashMap<String, String> keyValuePair = new HashMap<>();
    keyValuePair.put(
            "title",
            keyToStringIdValuePair.containsKey("installPkgs_autoAllowPkgs_allows") ?
                    keyToStringIdValuePair.get("installPkgs_autoAllowPkgs_allows") :
                    "installPkgs_autoAllowPkgs_allows"
    );
    keyValuePair.put("spKey", "installPkgs_autoAllowPkgs_allows");
    keyValuePair.put("category", "installPkgs_autoAllowPkgs_allows");
    list.add(keyValuePair);
}
 
Example 4
Source File: ParticleCloudException.java    From particle-android with Apache License 2.0 6 votes vote down vote up
private List<String> getErrors(JSONObject jsonObject) throws JSONException {
    List<String> errors = list();
    JSONArray jsonArray = jsonObject.getJSONArray("errors");
    if (jsonArray == null || jsonArray.length() == 0) {
        return errors;
    }
    for (int i = 0; i < jsonArray.length(); i++) {
        String msg;

        JSONObject msgObj = jsonArray.optJSONObject(i);
        if (msgObj != null) {
            msg = msgObj.getString("message");
        } else {
            msg = jsonArray.get(i).toString();
        }

        errors.add(msg);
    }

    return errors;
}
 
Example 5
Source File: ac.java    From letv with Apache License 2.0 6 votes vote down vote up
private static void a(Context context, JSONObject jSONObject, JSONArray jSONArray, ArrayList<JSONArray> arrayList) {
    if (arrayList.size() == 1) {
        b(context);
    } else if (jSONArray != null && arrayList.size() > 1) {
        arrayList.remove(jSONArray);
        JSONArray jSONArray2 = new JSONArray();
        for (int i = 0; i < arrayList.size(); i++) {
            JSONArray jSONArray3 = (JSONArray) arrayList.get(i);
            for (int i2 = 0; i2 < jSONArray3.length(); i2++) {
                if (jSONArray3.optJSONObject(i2) != null) {
                    jSONArray2.put(jSONArray3.optJSONObject(i2));
                }
            }
        }
        try {
            jSONObject.put(z[6], jSONArray2);
        } catch (JSONException e) {
        }
        a = jSONObject;
        a(context, z[11], jSONObject);
    }
}
 
Example 6
Source File: FreshNews.java    From JianDan_OkHttpWithVolley with Apache License 2.0 6 votes vote down vote up
public static ArrayList<FreshNews> parse(JSONArray postsArray) {

        ArrayList<FreshNews> freshNewses = new ArrayList<>();

        for (int i = 0; i < postsArray.length(); i++) {

            FreshNews freshNews = new FreshNews();
            JSONObject jsonObject = postsArray.optJSONObject(i);

            freshNews.setId(jsonObject.optString("id"));
            freshNews.setUrl(jsonObject.optString("url"));
            freshNews.setTitle(jsonObject.optString("title"));
            freshNews.setDate(jsonObject.optString("date"));
            freshNews.setComment_count(jsonObject.optString("comment_count"));
            freshNews.setAuthor(Author.parse(jsonObject.optJSONObject("author")));
            freshNews.setCustomFields(CustomFields.parse(jsonObject.optJSONObject("custom_fields")));
            freshNews.setTags(Tags.parse(jsonObject.optJSONArray("tags")));

            freshNewses.add(freshNews);

        }
        return freshNewses;
    }
 
Example 7
Source File: UserQueryService.java    From symphonyx with Apache License 2.0 6 votes vote down vote up
/**
 * Gets all members of a team specified by the given team name.
 *
 * @param teamName the given team name
 * @return all members
 */
public List<JSONObject> getTeamMembers(final String teamName) {
    final Query query = new Query().setFilter(CompositeFilterOperator.and(
            new PropertyFilter(UserExt.USER_TEAM, FilterOperator.EQUAL, teamName),
            new PropertyFilter(UserExt.USER_STATUS, FilterOperator.EQUAL, UserExt.USER_STATUS_C_VALID)));

    try {
        final JSONObject result = userRepository.get(query);

        final JSONArray users = result.optJSONArray(Keys.RESULTS);
        for (int i = 0; i < users.length(); i++) {
            final JSONObject user = users.optJSONObject(i);
            avatarQueryService.fillUserAvatarURL(user);
        }

        return CollectionUtils.<JSONObject>jsonArrayToList(result.optJSONArray(Keys.RESULTS));
    } catch (final RepositoryException e) {
        LOGGER.log(Level.ERROR, "Gets team members failed", e);

        return Collections.emptyList();
    }
}
 
Example 8
Source File: Deployments.java    From OpenMapKitAndroid with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private void parseJsonFromApi(String json) {
    try {
        JSONArray jsonFromAPI = new JSONArray(json);
        int len = jsonFromAPI.length();
        for (int i = 0; i < len; ++i) {
            JSONObject obj = jsonFromAPI.optJSONObject(i);
            if (obj != null) {
                obj.put("api", true);
                putDeployment(obj);
            }
        }

    } catch (JSONException e) {
        e.printStackTrace();
    }
}
 
Example 9
Source File: KlyphQuery.java    From Klyph with MIT License 5 votes vote down vote up
protected void assocStreamToObjectBySubPostId(JSONArray left, JSONArray right, String rightId, String leftParam)
{
	int n = left.length();
	int m = right.length();
	for (int i = 0; i < n; i++)
	{
		JSONObject leftObject = left.optJSONObject(i);
		String leftIdValue = leftObject.optString("post_id");

		int index = leftIdValue.indexOf("_");
		leftIdValue = leftIdValue.substring(index + 1);

		for (int j = 0; j < m; j++)
		{
			JSONObject rightObject = right.optJSONObject(j);
			String rightIdValue = rightObject.optString(rightId);

			if (leftIdValue.equals(rightIdValue))
			{
				try
				{
					leftObject.putOpt(leftParam, rightObject);
				}
				catch (JSONException e)
				{
					e.printStackTrace();
				}
			}
		}
	}
}
 
Example 10
Source File: JournalQueryService.java    From symphonyx with Apache License 2.0 5 votes vote down vote up
private List<JSONObject> getTeamMembers(final JSONObject archive, final String teamName) {
    try {
        final JSONArray teams = new JSONArray(archive.optString(Archive.ARCHIVE_TEAMS));

        final List<JSONObject> ret = new ArrayList<JSONObject>();

        for (int i = 0; i < teams.length(); i++) {
            final JSONObject team = teams.optJSONObject(i);
            final String name = team.optString(Common.TEAM_NAME);

            if (name.equals(teamName)) {
                final JSONArray members = team.optJSONArray(User.USERS);

                for (int j = 0; j < members.length(); j++) {
                    final JSONObject member = new JSONObject();
                    final String userId = members.optString(j);
                    member.put(Keys.OBJECT_ID, userId);

                    final JSONObject u = userRepository.get(userId);
                    member.put(User.USER_NAME, u.optString(User.USER_NAME));
                    member.put(UserExt.USER_AVATAR_URL, u.optString(UserExt.USER_AVATAR_URL));
                    member.put(UserExt.USER_UPDATE_TIME, u.opt(UserExt.USER_UPDATE_TIME));
                    member.put(UserExt.USER_REAL_NAME, u.optString(UserExt.USER_REAL_NAME));

                    ret.add(member);
                }

                return ret;
            }
        }
    } catch (final Exception e) {
        LOGGER.log(Level.ERROR, "Gets team members with archive[ " + archive + "] failed", archive);
    }

    return null;
}
 
Example 11
Source File: AnimatablePathValue.java    From atlas with Apache License 2.0 5 votes vote down vote up
AnimatablePathValue(Object json, LottieComposition composition) {
  if (hasKeyframes(json)) {
    JSONArray jsonArray = (JSONArray) json;
    int length = jsonArray.length();
    for (int i = 0; i < length; i++) {
      JSONObject jsonKeyframe = jsonArray.optJSONObject(i);
      PathKeyframe keyframe = PathKeyframe.Factory.newInstance(jsonKeyframe, composition,
          ValueFactory.INSTANCE);
      keyframes.add(keyframe);
    }
    Keyframe.setEndFrames(keyframes);
  } else {
    initialPoint = JsonUtils.pointFromJsonArray((JSONArray) json, composition.getDpScale());
  }
}
 
Example 12
Source File: LottieComposition.java    From atlas with Apache License 2.0 5 votes vote down vote up
private static void parseImages(
    @Nullable JSONArray assetsJson, LottieComposition composition) {
  if (assetsJson == null) {
    return;
  }
  int length = assetsJson.length();
  for (int i = 0; i < length; i++) {
    JSONObject assetJson = assetsJson.optJSONObject(i);
    if (!assetJson.has("p")) {
      continue;
    }
    LottieImageAsset image = LottieImageAsset.Factory.newInstance(assetJson);
    composition.images.put(image.getId(), image);
  }
}
 
Example 13
Source File: ElementAlbumRequest.java    From Klyph with MIT License 4 votes vote down vote up
@Override
public ArrayList<GraphObject> handleResult(JSONArray[] result)
{
	JSONArray data = result[0];
	JSONArray photos = result[1];

	assocData(data, photos, "cover_pid", "pid", "cover_images", "images");

	int n = 25;

	Album taggedAlbum = null;
	Album videoAlbum = null;

	if (result.length == 6)
	{
		JSONArray tagged = result[2];
		JSONArray user = result[3];
		JSONArray profile = result[4];

		PhotoDeserializer pd = new PhotoDeserializer();
		List<GraphObject> taggedPhotos = pd.deserializeArray(tagged);

		int nt = taggedPhotos.size();
		if (nt > 0)
		{
			taggedAlbum = new Album();
			taggedAlbum.setOwner(id);
			taggedAlbum.setPhoto_count(nt);
			taggedAlbum.setVideo_count(0);
			taggedAlbum.setIsTaggedAlbum(true);
			taggedAlbum.setIs_video_album(false);

			String eName = "";
			if (user.length() > 0)
			{
				UserDeserializer ud = new UserDeserializer();
				User u = (User) ud.deserializeArray(user).get(0);
				eName = u.getFirst_name().length() > 0 ? u.getFirst_name() : u.getName();
			}
			else if (profile.length() > 0)
			{
				ProfileDeserializer prd = new ProfileDeserializer();
				Profile p = (Profile) prd.deserializeArray(profile).get(0);
				eName = p.getName();
			}
			taggedAlbum.setName(KlyphApplication.getInstance().getString(R.string.tagged_photos_of, eName));

			Photo photo = (Photo) taggedPhotos.get(0);
			taggedAlbum.setCover_pid(photo.getPid());
			taggedAlbum.setCover_images(photo.getImages());
		}

		JSONArray videos = result[5];

		if (videos.length() > 0)
		{
			videoAlbum = new Album();
			videoAlbum.setOwner(id);
			videoAlbum.setPhoto_count(nt);
			videoAlbum.setVideo_count(0);
			videoAlbum.setIsTaggedAlbum(false);
			videoAlbum.setIs_video_album(true);

			for (int i = 0; i < videos.length(); i++)
			{
				JSONObject v = videos.optJSONObject(i);

				if (v != null && v.optString("thumbnail_link") != null)
				{
					Image cover = new Photo.Image();
					cover.setSource(v.optString("thumbnail_link"));

					List<Image> images = new ArrayList<Photo.Image>();
					images.add(cover);

					videoAlbum.setOwner(v.optString("owner"));
					videoAlbum.setCover_images(images);
					break;
				}
			}
		}
	}

	AlbumDeserializer deserializer = new AlbumDeserializer();

	ArrayList<GraphObject> albums = (ArrayList<GraphObject>) deserializer.deserializeArray(data);

	if (videoAlbum != null)
		albums.add(0, videoAlbum);
	
	if (taggedAlbum != null)
		albums.add(0, taggedAlbum);

	setHasMoreData(albums.size() >= n);

	return albums;
}
 
Example 14
Source File: GraphRequest.java    From kognitivo with Apache License 2.0 4 votes vote down vote up
/**
 * Sets the callback which will be called when the request finishes.
 *
 * @param callback the callback
 */
public final void setCallback(final Callback callback) {
    // Wrap callback to parse debug response if Graph Debug Mode is Enabled.
    if (FacebookSdk.isLoggingBehaviorEnabled(LoggingBehavior.GRAPH_API_DEBUG_INFO)
            || FacebookSdk.isLoggingBehaviorEnabled(LoggingBehavior.GRAPH_API_DEBUG_WARNING)) {
        Callback wrapper = new Callback() {
            @Override
            public void onCompleted(GraphResponse response) {
                JSONObject responseObject = response.getJSONObject();
                JSONObject debug =
                        responseObject != null ? responseObject.optJSONObject(DEBUG_KEY) : null;
                JSONArray debugMessages =
                        debug != null ? debug.optJSONArray(DEBUG_MESSAGES_KEY) : null;
                if (debugMessages != null) {
                    for (int i = 0; i < debugMessages.length(); ++i) {
                        JSONObject debugMessageObject = debugMessages.optJSONObject(i);
                        String debugMessage = debugMessageObject != null
                                ? debugMessageObject.optString(DEBUG_MESSAGE_KEY)
                                : null;
                        String debugMessageType = debugMessageObject != null
                                ? debugMessageObject.optString(DEBUG_MESSAGE_TYPE_KEY)
                                : null;
                        String debugMessageLink = debugMessageObject != null
                                ? debugMessageObject.optString(DEBUG_MESSAGE_LINK_KEY)
                                : null;
                        if (debugMessage != null && debugMessageType != null) {
                            LoggingBehavior behavior = LoggingBehavior.GRAPH_API_DEBUG_INFO;
                            if (debugMessageType.equals("warning")) {
                                behavior = LoggingBehavior.GRAPH_API_DEBUG_WARNING;
                            }
                            if (!Utility.isNullOrEmpty(debugMessageLink)) {
                                debugMessage += " Link: " + debugMessageLink;
                            }
                            Logger.log(behavior, TAG, debugMessage);
                        }
                    }
                }
                if (callback != null) {
                    callback.onCompleted(response);
                }
            }
        };
        this.callback = wrapper;
    } else {
        this.callback = callback;
    }

}
 
Example 15
Source File: CommentsRequest.java    From Klyph with MIT License 4 votes vote down vote up
@Override
public ArrayList<GraphObject> handleResult(JSONArray result)
{
	JSONArray jsonArray = new JSONArray();
	
	int n = result.length();
	for (int i = 0; i < n; i++)
	{
		JSONObject comment = result.optJSONObject(i);
		
		if (comment != null)
		{
			JSONObject parent = comment.optJSONObject("parent");
			
			// If this is a reply, then we skip it
			if (parent != null)
			{
				continue;
			}
			
			jsonArray.put(comment);
			
			JSONObject subComments = comment.optJSONObject("comments");
			
			if (subComments != null)
			{
				JSONArray data = subComments.optJSONArray("data");
				
				if (data != null)
				{
					int m = data.length();
					for (int j = 0; j < m; j++)
					{
						JSONObject subComment = data.optJSONObject(j);
						
						if (subComment != null)
						{
							jsonArray.put(subComment);
						}
					}
				}
			}
		}
	}
	
	CommentDeserializer deserializer = new CommentDeserializer();
	ArrayList<GraphObject> comments = (ArrayList<GraphObject>) deserializer.deserializeArray(jsonArray);
	
	setHasMoreData(comments.size() > 0);

	return comments;
}
 
Example 16
Source File: BackupUtils.java    From FreezeYou with Apache License 2.0 4 votes vote down vote up
private static boolean importUserTimeTasksJSONArray(Context context, JSONObject jsonObject) {
    JSONArray userTimeScheduledTasksJSONArray =
            jsonObject.optJSONArray("userTimeScheduledTasks");
    if (userTimeScheduledTasksJSONArray == null) {
        return false;
    }

    SQLiteDatabase db = context.openOrCreateDatabase("scheduledTasks", MODE_PRIVATE, null);
    db.execSQL(
            "create table if not exists tasks(_id integer primary key autoincrement,hour integer(2),minutes integer(2),repeat varchar,enabled integer(1),label varchar,task varchar,column1 varchar,column2 varchar)"
    );

    boolean isCompletelySuccess = true;
    JSONObject oneUserTimeScheduledTaskJSONObject;
    for (int i = 0; i < userTimeScheduledTasksJSONArray.length(); ++i) {
        try {
            oneUserTimeScheduledTaskJSONObject = userTimeScheduledTasksJSONArray.optJSONObject(i);
            if (oneUserTimeScheduledTaskJSONObject == null) {
                isCompletelySuccess = false;
                continue;
            }
            if (oneUserTimeScheduledTaskJSONObject.optBoolean("doNotImport", false)) {
                continue;
            }
            db.execSQL(
                    "insert into tasks(_id,hour,minutes,repeat,enabled,label,task,column1,column2) values(null,"
                            + oneUserTimeScheduledTaskJSONObject.getInt("hour") + ","
                            + oneUserTimeScheduledTaskJSONObject.getInt("minutes") + ","
                            + oneUserTimeScheduledTaskJSONObject.getString("repeat") + ","
                            + oneUserTimeScheduledTaskJSONObject.getInt("enabled") + ","
                            + "'" + oneUserTimeScheduledTaskJSONObject.getString("label") + "'" + ","
                            + "'" + oneUserTimeScheduledTaskJSONObject.getString("task") + "'" + ",'','')"
            );
        } catch (JSONException e) {
            isCompletelySuccess = false;
        }
    }

    db.close();
    TasksUtils.checkTimeTasks(context);

    return isCompletelySuccess;
}
 
Example 17
Source File: TrackHelper.java    From VideoOS-Android-SDK with GNU General Public License v3.0 4 votes vote down vote up
private static HashMap<String, String> buildPostParams(JSONArray cacheJsonArray) {
    HashMap<String, String> postParams = new HashMap<>();

    StringBuilder sidBuilder = new StringBuilder("[");
    StringBuilder oidBuilder = new StringBuilder("[");
    StringBuilder vidBuilder = new StringBuilder("[");
    StringBuilder chBuilder = new StringBuilder("[");
    StringBuilder brBuilder = new StringBuilder("[");
    StringBuilder iidBuilder = new StringBuilder("[");
    StringBuilder catBuilder = new StringBuilder("[");
    StringBuilder tidBuilder = new StringBuilder("[");

    for (int i = 0, len = cacheJsonArray.length(); i < len; i++) {
        JSONObject jsonObj = cacheJsonArray.optJSONObject(i);

        sidBuilder.append(jsonObj.opt("mSsId"));
        oidBuilder.append(jsonObj.opt("mObjectId"));
        vidBuilder.append(jsonObj.opt("mVideoId"));
        chBuilder.append(jsonObj.opt("mChannelId"));
        brBuilder.append(jsonObj.opt("mBrandId"));
        iidBuilder.append(jsonObj.opt("mInfoId"));
        catBuilder.append(jsonObj.opt("mCat"));
        tidBuilder.append(jsonObj.opt("mTargetIds"));

        if (i != len - 1) {
            sidBuilder.append(",");
            oidBuilder.append(",");
            vidBuilder.append(",");
            chBuilder.append(",");
            brBuilder.append(",");
            iidBuilder.append(",");
            catBuilder.append(",");
            tidBuilder.append(",");
        }
    }//end for

    sidBuilder.append("]");
    oidBuilder.append("]");
    vidBuilder.append("]");
    chBuilder.append("]");
    brBuilder.append("]");
    iidBuilder.append("]");
    catBuilder.append("]");
    tidBuilder.append("]");

    postParams.put(TRACK_SID, sidBuilder.toString());
    postParams.put(TRACK_OBJECT_ID, oidBuilder.toString());
    postParams.put(TRACK_VIDED_ID, vidBuilder.toString());
    postParams.put(TRACK_CHANNEL_ID, chBuilder.toString());
    postParams.put(TRACK_BRAND_ID, brBuilder.toString());
    postParams.put(TRACK_INFO_ID, iidBuilder.toString());
    postParams.put(TRACK_CAT, catBuilder.toString());
    postParams.put(TRACK_TARGET_ID, tidBuilder.toString());

    return postParams;
}
 
Example 18
Source File: SearchActivity.java    From Simpler with Apache License 2.0 4 votes vote down vote up
public void queryDailyHotTopic(String nextPage, final boolean refresh) {
        String url;
        if (nextPage == null) {
            url = TOPIC_URL;
        } else {
            url = TOPIC_URL + "&since_id=" + nextPage;
        }

        if (!TextUtils.isEmpty(mCookie)) {
            HttpGetTask task = new HttpGetTask(true, new HttpListener() {
                @Override
                public void onResponse(String response) {
                    mSwipeRefresh.setRefreshing(false);
//                    Log.d("Topic", response);
                    if (!TextUtils.isEmpty(response)) {
                        try {
                            List<Topic> topicList = new ArrayList<>();
                            JSONObject obj = new JSONObject(response);
                            JSONArray cards = obj.optJSONArray("cards");
                            JSONObject cardlistInfo = obj.optJSONObject("cardlistInfo");
                            if (cardlistInfo != null) {
                                mNextPage = cardlistInfo.optString("since_id", null);
                            } else {
                                mNextPage = null;
                            }
                            if (cards != null && cards.length() > 0) {
                                JSONArray array = cards.optJSONObject(0).optJSONArray("card_group");
                                if (array != null && array.length() > 0) {
                                    for (int i = 0; i < array.length(); i++) {
                                        JSONObject topic = array.optJSONObject(i);
                                        topicList.add(Topic.parse(topic));
                                    }
                                }
                            }
                            if (refresh) {
                                mAdapter.setTopics(topicList);
                            } else {
                                mAdapter.addTopics(topicList);
                            }
                            if (mNextPage != null) {
                                mAdapter.setFooterInfo(getString(R.string.pull_up_to_load_more));
                            } else {
                                mAdapter.setFooterInfo(getString(R.string.no_more_data));
                            }
                        } catch (JSONException e) {
                            e.printStackTrace();
                            AppToast.showToast(R.string.update_web_wb_cookie);
                            startActivity(WebWBActivity.newIntent(SearchActivity.this, true));
                        }
                    }
                }

                @Override
                public void onFailure() {
                    mSwipeRefresh.setRefreshing(false);
                    AppToast.showToast("获取热门话题失败");
                }
            });
            task.execute(url, mCookie);
            registerAsyncTask(SearchActivity.class, task);
        } else {
            // Cookie为空
            mSwipeRefresh.setRefreshing(false);
        }
    }
 
Example 19
Source File: VideoBean.java    From letv with Apache License 2.0 4 votes vote down vote up
public static VideoBean parse(JSONObject obj) {
    boolean z = true;
    VideoBean video = new VideoBean();
    video.vid = obj.optLong("vid");
    video.pid = obj.optLong("pid");
    video.cid = obj.optInt("cid");
    video.zid = obj.optString(PlayConstant.ZID);
    video.nameCn = obj.optString("nameCn");
    video.subTitle = obj.optString("subTitle");
    video.singer = obj.optString("singer");
    video.releaseDate = obj.optString("releaseDate");
    video.style = obj.optString("style");
    video.playMark = obj.optString("playMark");
    video.vtypeFlag = obj.optString("vtypeFlag");
    video.guest = obj.optString("guest");
    video.type = obj.optInt("type");
    video.btime = obj.optLong(DownloadVideoTable.COLUMN_BTIME);
    video.etime = obj.optLong(DownloadVideoTable.COLUMN_ETIME);
    video.duration = obj.optLong(DownloadVideoTable.COLUMN_DURATION);
    video.mid = obj.optString("mid");
    video.episode = obj.optString("episode");
    video.porder = obj.optString("porder");
    video.pay = obj.optInt("pay");
    video.albumPay = obj.optInt("album_pay");
    video.download = obj.optInt("download");
    JSONObject picAll = obj.optJSONObject("picAll");
    if (picAll != null) {
        video.pic320_200 = picAll.optString("320*200");
        video.pic120_90 = picAll.optString("120*90");
    }
    if (!TextUtils.isEmpty(obj.optString("mobilePic"))) {
        video.pic320_200 = obj.optString("mobilePic");
    }
    video.play = obj.optInt("play");
    video.openby = obj.optInt("openby");
    video.jump = obj.optInt("jump");
    video.jumptype = obj.optString("jumptype");
    video.jumpLink = obj.optString("jumplink");
    video.isDanmaku = obj.optInt("isDanmaku");
    video.brList = obj.optString("brList");
    video.videoTypeKey = obj.optString(DownloadVideoTable.COLUMN_VIDEOTYPEKEY);
    video.videoType = obj.optString(PlayConstant.VIDEO_TYPE);
    video.videoTypeName = obj.optString("videoTypeName");
    video.controlAreas = obj.optString("controlAreas");
    video.disableType = obj.optInt("disableType");
    video.cornerMark = obj.optString("cornerMark");
    video.playCount = obj.optLong("playCount");
    video.score = obj.optString("score");
    video.director = obj.optString("director");
    video.starring = obj.optString("starring");
    video.reid = obj.optString("reid");
    video.bucket = obj.optString("bucket");
    video.area = obj.optString("area");
    video.isRec = obj.optBoolean("is_rec", false);
    video.dataArea = obj.optString("dataArea");
    video.subCategory = obj.optString("subCategory");
    video.title = obj.optString("title");
    video.pidname = obj.optString("pidname");
    video.subname = obj.optString("subname");
    video.pidsubtitle = obj.optString("pidsubtitle");
    video.picHT = obj.optString("picHT");
    video.picST = obj.optString("picST");
    video.at = obj.optInt(PushDataParser.AT);
    video.createYear = obj.optString("createYear");
    video.createMonth = obj.optString("createMonth");
    video.noCopyright = TextUtils.equals(obj.optString(PlayConstant.NO_COPYRIGHT), "1");
    video.externalUrl = obj.optString("external_url");
    video.isAlbum = obj.optString("isalbum");
    if (LetvUtils.stringToInt(obj.optString(DownloadVideoTable.COLUMN_ISVIP_DOWNLOAD)) != 1) {
        z = false;
    }
    video.isVipDownload = z;
    JSONArray jsonFocusrray = obj.optJSONArray("watchingFocus");
    if (jsonFocusrray != null && jsonFocusrray.length() > 0) {
        int len = jsonFocusrray.length();
        for (int j = 0; j < len; j++) {
            JSONObject jsonFocusObj = jsonFocusrray.optJSONObject(j);
            WatchingFocusItem mWatchingFocusItem = new WatchingFocusItem();
            mWatchingFocusItem.desc = jsonFocusObj.optString(SocialConstants.PARAM_APP_DESC);
            mWatchingFocusItem.id = jsonFocusObj.optInt("id");
            mWatchingFocusItem.picUrl = jsonFocusObj.optString(DownloadBaseColumns.COLUMN_PIC);
            mWatchingFocusItem.timeDot = jsonFocusObj.optString("time");
            video.watchingFocusList.add(mWatchingFocusItem);
        }
    }
    return video;
}
 
Example 20
Source File: DeliciousURLExtractor.java    From wandora with GNU General Public License v3.0 4 votes vote down vote up
private boolean extract(final Topic topic) throws ExtractionFailure, TopicMapException
{
    ArrayList<String> urlList = new ArrayList<String>();
    
    for(Locator l : topic.getSubjectIdentifiers())
    {
        urlList.add(l.toString());
    }
    
    if(topic.getSubjectLocator() != null)
        urlList.add(topic.getSubjectLocator().toString());
    log("Found " + urlList.size() + " url(s) to check.");
    final JSONArray result = doRequest(urlList);
    
    if(result.length() == 0)
    {
        log("No results available.");
        return false;
    }
    
    Topic deliciousT = getDeliciousClass(currentMap);
    Topic tagT = FlickrUtils.createTopic(currentMap, "delicious tag", deliciousT);
    Topic tagAssoc = FlickrUtils.createTopic(currentMap, "describes", deliciousT);
    Topic tagTargetT = FlickrUtils.createTopic(currentMap, "descriptee", deliciousT);
    
    boolean success = false;
    
    for(int i = 0; i < result.length(); ++i)
    {
        final JSONObject resultObj = result.optJSONObject(i);
        if(resultObj == null)
            throw new RequestFailure("Unable to get inner object");

        final JSONObject tagsObj = resultObj.optJSONObject("top_tags");
        if(tagsObj == null)
        {
            log("No results for url[" + i + "]");
            continue;
        }

        log("Extracting tags");
        for(String s : new Iterable<String>() { public Iterator<String> iterator() { return tagsObj.keys(); }})
        {
            log("Extracting tag " + s);
            Topic tag = FlickrUtils.createRaw(currentMap, "http://delicious.com/tag/" + url(s), " (delicious tag)", s, tagT);
            FlickrUtils.createAssociation(currentMap, tagAssoc, new Topic[] { tag, topic }, new Topic[]{tagT, tagTargetT});
        }
        success = true;
    }
    
    return success;
}